Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda timeout on sqs sendmessage

I'm sending messages to a queue from a lambda function. But some times sqs.sendMessage dont return anything and the lambda get timeout. This happens sometimes

I tried changing de code many times, to work with await, promises and callback but the error persist.

Lambda log

const sqs = new aws.SQS({apiVersion: '2012-11-05'});

//TODO: Validar campos obrigatórios nas mensagens de acordo com o tipo de mensagem
exports.sendMessage =  async (message) => {
  let params = {
    MessageBody: JSON.stringify(message),
    QueueUrl: 'https://sqs.us-east-1.amazonaws.com/....',
  };

  try {
    await sqs.sendMessage(params).promise();
    return {statusCode: 200, body: {data: "Notification sent successfully"}};
  } catch (e) {
    return {statusCode: 400, body: {data: e}};
  }
}
like image 720
Fortunato Avatar asked Nov 07 '22 14:11

Fortunato


1 Answers

I had a similar issues. What I did to make it work was add in the endpoint url into the boto3 client call.

For Example: boto3.client('sqs',endpoint_url='https://YourVPCDNSEndpointforSQS')

like image 86
AnonCoder Avatar answered Nov 17 '22 10:11

AnonCoder