Review retention of failed Serverless asynchronous events

Provide a recovery path for failed asynchronous events.

Description

Use onError to send discarded asynchronous Lambda events to an SNS topic when retries run out or events expire.

Potential impact

A subscriber must retain the failed events so you can inspect and reprocess them.

Remediation

Set onError to a standard SNS topic ARN. Allow the execution role to publish to it and verify delivery to a subscriber. Handle synchronous errors in the caller. For SQS triggers, configure a dead-letter queue on the source queue.

Examples

Set failureTopicArn to your topic ARN and supply a Node.js 22 handler.hello for this Framework 4 service.

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