Lambda Asynchronous Invocation

Pasted image 20221009200304.png

  • Aysnchronous invokation happens when other services execute lambda.

  • Services that will execute Async lambda

    • S3
    • SNS
    • CloudWatch Events/ EventBridge
    • CodeCommit
    • CodePipeline
    • Cli
    • ... and some other services
  • Events will go to an Lambda Event Queue

  • On error, attempts retries 2 times in total

    • 1st time: wait 1 minute
    • 2nd time: wait 2 minute
  • Make sure the lambda function is idempotent

    • which mean incase of retries, the result is the same
    • For retrying it will use the same RequestID
  • If retries happen, you might see duplicate logs in CloudWatch Logs

  • We can define a Dead Letter Queue (SNS or SQS) for failed process (after retries)

    • Note: for SNS Dead Letter Queue, if there are no SNS receiver, the message will be lost.

Invoke Asynchronously on CLI

We set --invocation-type to Event (default RequestResponse which invokes synchronously)