5

I created below resources using CloudFormation

  • SQS (DelayDelivery : 0)
  • Lambda
  • Roles
  • LambdaFunctionEventSourceMapping (SQS Triggers a Lambda function)
  • Logs

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.

3
  • What are you using to generate messages for SQS? Why do you want to delay your lambda execution instead of delivery delay? In that case, you have to pay for an extra 30 seconds. Commented Oct 5, 2018 at 16:02
  • Messages are generate by PHP Application and sent to SQS. I do not want the delay in Lambda execution. When I send a message to SQS, a lambda is trigger. Even if a message has delay delivery Commented Oct 8, 2018 at 1:50
  • I've just realized that by using aws web interface. Same stuff, triggered lambda fn immediately Commented Apr 4, 2019 at 23:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.