Arjun
Arjun

Reputation: 143

Configurable Cron job in Lambda

I am trying to figure out how I can set up a conditional cron job in Lambda for my below Scenario:

I have an SQS queue and I have to create a Lambda function which publish a message to SNS only in between 7 AM to 5 PM if we have a delayed message attribute set in the SQS. So basically this Lambda will act as a subscriber for SQS and publisher for SNS.

So just wondering how we can make the cron job conditional based upon the SQS message attributes?

Upvotes: 3

Views: 1110

Answers (1)

Ethan Harris
Ethan Harris

Reputation: 1362

You could set the Lambda function to trigger off a CloudWatch Logs cron event, then poll through SQS messages in the Lambda function to search for the delayed message attribute.

To set up the cron trigger:

  • Navigate to CloudWatch in the console
  • Events > Rules > Create Rule
  • Select Schedule > Cron expression > cron(0/10 2-7 * * ? *)
  • For Target, select your Lambda function.

This will trigger your Lambda function to run every 10 minutes between 02:00-07:00 UTC every day. Inside the Lambda function if will be up to you to pull messages from the queue and delete from the queue when consumed by the Lambda function.

Upvotes: 2

Related Questions