Home > Mobile >  Having a CloudWatch Event trigger an SQS send to Lambda
Having a CloudWatch Event trigger an SQS send to Lambda

Time:05-04

I have a lambda that makes web requests depending on attributes of a message coming in via API Gateway. When the web request fails, I drop the event in a queue to be processed at a later time.

Since there is a likelihood that the external service is down as the reason for the failed request, I want to retry the request but not immediately.

I know I can have the queue be a trigger for the lambda, but I don't want it to trigger immediately on a new message arriving. I'd rather have it wait for 5 minutes or so and then have the SQS trigger the lambda.

My current solution has another lambda, that is triggered by a CloudWatch event, pull from the queue and then resend the messages to the lambda that makes requests. I feel like this solution is sloppy since I'm building a cloud watch event and another lambda just to handle a retry.

Is there a way for the SQS to trigger the Lambda on a time interval rather than on enqueue? Is there a better way to handle this?

CodePudding user response:

Is there a way for the SQS to trigger the Lambda on a time interval rather than on enqueue? Is there a better way to handle this?

Yes, you can setup SQS delay queues with the delay of up to 15 minutes.

  • Related