Lesson 2 of 3 AWS Lambda and Amazon SQS Operations

Handling Lambda Failures and Releasing Changes with Aliases

This lesson explains how Lambda failure handling depends on invocation type, how operators configure retries, destinations and dead-letter queues so failed events are not lost, and how versions and aliases release changes safely.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain retries for each invocation type.
  • Capture failures with destinations and dead-letter queues.
  • Shift traffic with versions and weighted aliases.

Invocation types and retries

With synchronous invocation (API Gateway, ALB, SDK calls), the caller receives the error and decides whether to retry. With asynchronous invocation (S3 Event Notifications, SNS, EventBridge), Lambda queues the event and retries failed invocations twice by default, with configurable maximum retry attempts (0 to 2) and maximum event age (up to 6 hours). With event source mappings (SQS, Kinesis, DynamoDB Streams), Lambda polls the source and retries according to the source's rules, covered in the next topic.

2retries

Default for failed asynchronous invocations

6hours

Maximum event age

Sort into groups

Who retries?

Exam skills 1.2.1 · 2.2.2

Decide how failures are retried for each invocation source.

Log in to try this activity Interactive activities are free with an account.

Destinations and dead-letter queues

For asynchronous invocations, destinations send a record of each successful or failed invocation, including the request, response and error details, to SQS, SNS, EventBridge, another Lambda function or S3. A dead-letter queue (SQS or SNS) receives only failed events and only the original payload, so on-failure destinations are the more capable modern option. The execution role needs permission to send to the destination.

True or false

Destinations and DLQs

Exam skills 1.2.1

Check facts about capturing failed asynchronous invocations.

Log in to try this activity Interactive activities are free with an account.

Versions, aliases and traffic shifting

Publishing a function creates an immutable, numbered version; $LATEST is the editable code. An alias such as prod points to a version, and callers invoke the alias ARN, so a release means moving the alias. An alias can have weighted routing to two versions, for example 90% to version 7 and 10% to version 8, which implements a canary release; CloudWatch metrics per version show whether the new version errors more. Rollback is moving the alias back. Provisioned concurrency is configured on a version or alias, not on $LATEST.

aws lambda publish-version --function-name orders
aws lambda update-alias --function-name orders --name prod --function-version 7 \
  --routing-config '{"AdditionalVersionWeights":{"8":0.1}}'
# promote fully after monitoring
aws lambda update-alias --function-name orders --name prod --function-version 8 --routing-config '{}'

The following diagram shows an alias splitting traffic between two versions.

A canary release with a Lambda alias. Callers invoke the prod alias, which sends 90% of invocations to version 7 and 10% to version 8. CloudWatch metrics per version show whether version 8 errors more; completing the release moves the alias fully to version 8, and rollback moves it back.
The versions and weights are illustrative.
Worked example

Losing failed events

A function invoked by S3 Event Notifications occasionally fails on malformed files, and the events disappear after Lambda's two retries. The operator adds an on-failure destination that sends records to an SQS queue, which captures the S3 event, the error message and the stack trace, and lowers maximum retry attempts to 1 because retrying a malformed file never succeeds. An alarm on the queue's ApproximateNumberOfMessagesVisible alerts the team to investigate.

Check yourself

How is a canary release done with Lambda aliases?

Show answer

Give an alias weighted routing, sending a small share of traffic to the new version.

Exam Tips

Remember for the exam

  • Asynchronous invocations retry twice by default; configure retries and maximum event age.
  • On-failure destinations capture the event and error; DLQs capture only the event.
  • Aliases point to versions; weighted aliases implement canary releases.
  • Provisioned concurrency applies to versions or aliases, not $LATEST.