Review retention of failed Lambda asynchronous events

Configure and test a DLQ or failure destination for Lambda asynchronous processing.

Description

Choose how to recover asynchronous Lambda events that exceed their retry or age limit. A DLQ is one option when you need to retain the failed inputs.

Potential impact

Unretained events and unnoticed delivery errors can leave gaps in processing that are difficult to recover.

Remediation

Use an asynchronous failure destination, or set dead_letter_config to a standard SQS queue or SNS topic ARN. Grant the execution role permission to send, check destination size limits and delivery errors, and test retention and replay. For an SQS event source, configure the DLQ on the source queue.

Examples

Supply an execution role and set var.lambda_runtime to a supported runtime compatible with lambda.zip.

Before

hcl
resource "aws_lambda_function" "example" {
  function_name = "lambdaWithoutDLQ"
  role          = aws_iam_role.lambda_exec_role.arn
  handler       = "index.handler"
  runtime       = var.lambda_runtime
  filename      = "lambda.zip"
}

After

hcl
resource "aws_lambda_function" "example" {
  function_name = "lambdaWithoutDLQ"
  role          = aws_iam_role.lambda_exec_role.arn
  handler       = "index.handler"
  runtime       = var.lambda_runtime
  filename      = "lambda.zip"

  dead_letter_config {
    target_arn = "arn:aws:sns:us-east-1:123456789012:my-dlq-topic"
  }
}

The second configuration sends failures from the same function to SNS. Subscribe the intended receiver and verify it receives and retains the failed inputs.

References