SAM function without retention for failed asynchronous events

Configure retention for events that asynchronous invocations cannot process.

Description

A Lambda function can keep failed asynchronous events in a dead-letter queue (DLQ) once it exhausts its retries or the events expire.

Potential impact

Without a copy of the event, you may have nothing to replay.

Remediation

Under DeadLetterQueue, set Type to SQS or SNS and TargetArn to the standard queue or topic ARN. Grant the execution role permission to send events. For SNS, add a subscriber that saves them. Use an on-failure destination for failure details. For an SQS trigger, set the DLQ on the source queue.

Examples

Supply your SQS queue ARN, image URI and container settings.

Before

yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: account-id.dkr.ecr.region.amazonaws.com/ecr-repo-name:image-name
      ImageConfig:
        Command:
          - app.lambda_handler
        EntryPoint:
          - entrypoint1
        WorkingDirectory: workDir
      Tags:
        Type: AWS Serverless Function

After

yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: account-id.dkr.ecr.region.amazonaws.com/ecr-repo-name:image-name
      ImageConfig:
        Command:
          - app.lambda_handler
        EntryPoint:
          - entrypoint1
        WorkingDirectory: workDir
      Tags:
        Type: AWS Serverless Function
      DeadLetterQueue:
        TargetArn: arn:aws:sqs:us-east-1:123456789012:aaa
        Type: SQS

References