Rafee
Rafee

Reputation: 4078

SQS triggers Lambda on Individual message delay delivery

I created below resources using CloudFormation

Resources created successfully.

When I send a message to SQS with Delay deliver for 30 seconds, SQS triggers Lambda instantaneously. Instead, it should have trigger after 30 seconds. FYI : I am sending message using AWS console.

As per below link, it should have override the SQS delay to individual message delay. https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-timers.html

Is there any other way to achieve this.

Upvotes: 5

Views: 2362

Answers (1)

riza
riza

Reputation: 691

This is possibly a bug with the AWS console, because I encounter similar issue (lambda invoked instantaneously) when I send the message to SQS via AWS console. However, I can achieve the desired behaviour if I send the message to SQS via CLI:

aws sqs send-message --queue-url https://sqs.ap-southeast-1.amazonaws.com/{account}/{sqs} --message-body "msg 1 delay 60 secs" --delay-seconds 60

aws sqs send-message --queue-url https://sqs.ap-southeast-1.amazonaws.com/{account}/{sqs} --message-body "msg 2 delay 30 secs" --delay-seconds 30

Then this is what I see in the lambda Cloudwatch log:

2019-02-19T02:26:36.189Z    510df77b-d1e5-5297-b0a0-a39eba727c61    msg 2 delay 30 secs
2019-02-19T02:26:36.189Z    510df77b-d1e5-5297-b0a0-a39eba727c61    sent 2019-02-19T02:26:06.124Z
2019-02-19T02:26:36.189Z    510df77b-d1e5-5297-b0a0-a39eba727c61    1st receive 2019-02-19T02:26:36.124Z

2019-02-19T02:26:57.729Z    fedcb590-2e14-596a-bc4b-e17545a46d91    msg 1 delay 60 secs
2019-02-19T02:26:57.729Z    fedcb590-2e14-596a-bc4b-e17545a46d91    sent 2019-02-19T02:25:57.667Z
2019-02-19T02:26:57.729Z    fedcb590-2e14-596a-bc4b-e17545a46d91    1st receive 2019-02-19T02:26:57.667Z

As you can see from the log, the messages delivery are properly delayed, and lambdas are only invoked once the message is received.

Upvotes: 2

Related Questions