Reputation: 143
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
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:
cron(0/10 2-7 * * ? *)
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