How to set DeadLetterQueue (DLQ) on AWS Lambda functions using the AWS CLI

UPDATE: It's important to note that as of now, DLQ's are ONLY supported in the us-east-2 (Ohio) region. While this command doesn't return any errors in other regions, it also doesn't make any changes.

One of the cooler announcements from re:Invent that you can start using right now is Dead Letter Queues (DLQ) for AWS Lambda functions. This has the advantage of allowing you to re-try, and alert, on events that fail even after being re-tried by AWS Lambda automatically.

You can find out more information on DLQ for Lambda by reading the official documentation, however in order to get quickly started with it, you should create a new SQS queue and configure a lambda function to send to it. This should be able to be done through the AWS Console, but it doesn't appear to be there yet, so here's how to get started with the CLI.

First, upgrade to the latest version:

sudo pip install -U awscli

Then, update your function:


aws lambda update-function-configuration --function-name LambdaFunctionName --dead-letter-config TargetArn=sqs or sns arn

That's it, you should start seeing DLQ events coming in on the SQS queue you configured anytime there is a complete failure, after Lambda's re-tries have all failed.

From here, you can set up alerts using SES, you could set this up to notify you via SNS, or have another Lambda function read the queue every few minutes to pick up and try re-processing the events at a later date.
0