Amiga500
Amiga500

Reputation: 6131

AWS - Lambda and SQS behavior

I have setup an SQS, DeadLetterQue (DLQ) and a lambda. I am having some questions regarding the body format that the SQS receives. After some tries, I can see some messages are ending up in a DLQ.

I have read many documentations, but really I still can't figure some basic things.

My task is fairly simple. I will use Axios to send some payload to external API. That API might give me an error, or not available at that time. This code is very simple, but at the end it will include Axios implementation:

exports.handler = async (event, context) => {   
    event.Records.forEach(record => {
    const { body } = record;
    const { messageAttributes } = record;
    console.log(body)
    console.log(messageAttributes);
  });  
    let somethingWentWrongWithApi = new Error();
    throw somethingWentWrongWithApi;    
}; 

After this is run, after some time I see message in DLQ, and original SQS is empty, as I expected.

In real code, I will have catch block. And inside it I will throw the error, exactly as in example. Lambda will try to execute it three times (I am not sure where I got this information). Then, it will return it to SQS, where in turn the SQS will push it to DLQ.

I wonder, should I implement in Lambda retries, and after three times throw the error... or just throw it and rely on existing process (three times retrial)?

I am still reading about different setting on both SQS and Lambda.

Upvotes: 0

Views: 314

Answers (1)

Nikolay Vetrov
Nikolay Vetrov

Reputation: 634

To extend execution tries you have to go to:

  1. SQS service;
  2. Right click on your SQS;
  3. Choose a configure Queue option;
  4. Under the Dead Letter Queue Settings line you can see a Maximum Receives property (which you can set between 1 and 1000).

About errors. If something going wrong on lambda side then lambda throwing an error, you can check what kind of errors throwed with cloudwatch.

  1. Go to aws CloudWatch;
  2. On the right panel find Logs;
  3. Chose Log Group.

If you have any additional questions just summon me. I'll try to answer them and I'll extend that answer.

Upvotes: 1

Related Questions