mrbusche.com

Setting up a cron job and processing the request in AWS Lambda

Setting up a cron job in AWS lambda is pretty trivial, but I struggled with how to take action when the event is triggered. Turns out it's pretty straightforward. The event['detail-type'] will be Scheduled Event.

myFunction:
  Type: AWS::Serverless::Function
  Properties:
    Handler: app.handler
    Events:
      myCron:
        Type: Schedule
        Properties:
          Schedule: 'cron(? 10 * * Mon *)'
if (event['detail-type'] === 'Scheduled Event') {
	console.log('cron triggered');
	return await somethingThatWasScheduled(event);
}