SQS Lambda - retry logic?

后端 未结 4 1207
忘了有多久
忘了有多久 2021-02-12 22:21

When the message has been added to an SQS queue and it is configured to trigger a lambda function (nodejs).

When a lambda function is triggered - I may want to retry sa

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-12 22:43

    Here is how I did it.

    1. Create Normal Queues (Immediate Delivery), Q1
    2. Create Delay Queues (5 mins delay), Q2
    3. Create DLQ (After retries), DLQ1

    (Q1/Q2) SQS Trigger --> Lambda L1 (if failed, delete on (Q1/Q2), drop it on Q2) --> On Failure DLQ

    When messages arrive on Q1 it triggers Lambda L1 if success goes from there. If fails, drop it to Q2 (which is a delayed queue). Every message that arrives on Q2 will have a delay of 5 minutes.

    If your initial message can have a delay of 5 mins, then you might not need two queues. One queue should be good. If the initial delay is not acceptable then you need two queues. One another reason to have two queues, you will always have a way for new messages that comes in the path.

    If you have a code failure in handling Q1/Q2 aws infrastructure will retry immediately for 3 times before it sends it to DLQ1. If you handle the error in the code, then you can get the pipeline to work with the timings you mentioned.

    SQS Delay Queues:

    https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-delay-queues.html

    SQS Lambda Architecture:

    https://nordcloud.com/amazon-sqs-as-a-lambda-event-source/

    Hope it helps.

提交回复
热议问题