1
votes

I have attempted to follow the documentation about setting up an SQS Dead Letter Queue for my Lambda on AWS but I can't seem to get the errors to pass through to it.

I have a Lambda on eu-west-2

exports.handler = async (event) => {
    if (event.desire === 'error') {
        throw new Error('dutifully throw an error');
    }
    
    const response = {
        statusCode: 200,
        body: JSON.stringify('Complete the lambda!'),
    };
    return response;
};

with asynchronous invocation set to my sqs queue test-dlq

asynchronous invocation settings

I've added the following into the role:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": "sqs:*",
            "Resource": "arn:aws:sqs:eu-west-2:123456789:test-dlq"
        }
    ]
}

(I've previously had this set to "Action": "sqs:SendMessage" but have made it more permissive for brevity)

And I've setup my SQS Queue to receive the messages:

enter image description here

My test case payload is:

{
    "desire": "error"
}

which causes the lambda to error and add the error to the CloudWatch log but doesn't pass to the DLQ.

Do I need to do anything to route the errors to the Queue or have I misconfigured this please?

1
How do you exactly invoke your function?Marcin
Just using the test button at the top right of the lambda function page in the console. I've also tried using the following on the command line: aws lambda invoke --function-name testFunction --payload '{"desire":"error"}' /tmp/out.jsonobie

1 Answers

3
votes

The reason why your DLQ does not work is because using Test button or invoking function using:

aws lambda invoke --function-name testFunction --payload '{"desire":"error"}' /tmp/out.json

result in synchronous invocations, rather then asynchronous ones.

To invoke your function asynchronously, you have to use Event type in the CLI:

aws lambda invoke --function-name testFunction --invocation-type Event --payload '{"desire":"error"}' /tmp/out.json