'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.
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}};
}
}
Solution 1:[1]
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')
Solution 2:[2]
I just had the same issue. The problem was that the lambda had 3 subnets assigned to it and only 1 of them had a routing entry to 0.0.0.0/0 Even tho 2/3 of the subnets were missing that routing entry, only 1-3% of the requests randomly timed out, so make sure to check that!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ultrasaurus |
| Solution 2 | cnknob |
