Review retention of failed Serverless asynchronous events

Provide a recovery path for failed asynchronous events.

Description

Lambda can send asynchronous events that remain unprocessed after retries to a DLQ or failure destination. Serverless Framework’s onError specifies an SNS topic; it does not replace failure handling for synchronous calls or SQS triggers.

Potential impact

Without a separate failure-retention path, events past their retry period can be difficult to investigate or reprocess.

Remediation

Choose failure handling for the invocation type. When using onError, configure an existing SNS topic, publish permissions, a subscriber that retains events, and a reprocessing procedure.

Examples

These excerpts require a separately supplied handler.hello compatible with Framework 4 and Node.js 22. Supply an existing SNS topic ARN as failureTopicArn.

Before

yaml
service: service
frameworkVersion: '4'
provider:
  name: aws
  runtime: nodejs22.x

functions:
  hello:
    handler: handler.hello

After

yaml
service: service
frameworkVersion: '4'
provider:
  name: aws
  runtime: nodejs22.x

functions:
  hello:
    handler: handler.hello
    onError: ${param:failureTopicArn}

References