Calling a lambda function once, it's executed twice

后端 未结 3 532
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 14:54

This is more of a concern than a question, but still, has anyone experienced this before? Does anyone know how to prevent it?

I have a lambda function (L1) which cal

相关标签:
3条回答
  • 2021-01-13 15:25

    Your lambda function must be idempotent, because it can be called twice in different situations.

    https://aws.amazon.com/premiumsupport/knowledge-center/lambda-function-idempotent/

    https://cloudonaut.io/your-lambda-function-might-execute-twice-deal-with-it/

    0 讨论(0)
  • 2021-01-13 15:25

    One case that may cause this is that in your L2 lambda you didn't return anything, which will lead the L1 lambda (the caller) to think there is an error with L2 and so the Retry mechanism is triggered. Try to return something in L2, even simply an "OK".

    0 讨论(0)
  • 2021-01-13 15:35

    With 10K lambda invokes it must be experiencing a failure and doing a retry.

    From the documentation:

    Asynchronous Invocation – Lambda retries function errors twice. If the function doesn't have enough capacity to handle all incoming requests, events may wait in the queue for hours or days to be sent to the function. You can configure a dead-letter queue on the function to capture events that were not successfully processed. For more information, see Asynchronous Invocation.

    If this is what is a happening and you setup the dead letter queue you'll be able to isolate the failure event.

    You can also use CloudWatch Logs Insights to easily and quickly search for errors messages of the lambda. Once you select the log group this query should help you get started. Just change the time window.

    fields @timestamp, @message
    | filter @message like /(?i)(Exception|error|fail|5\d\d)/
    | sort @timestamp desc
    | limit 20
    
    0 讨论(0)
提交回复
热议问题