aws-sdk services timing out in lambda nodejs

0

I am currently working on a lambda function in which I have to send a message to an SQS queue. The Lambda function sits inside of a VPC to allow connection with a peered network that the Function makes requests to.

Whenever I try to send the message to SQS however code execution seems to timeout consistently. I had the same issue when I was trying to send commands to DynamoDB.

import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";

const sqsClient = new SQSClient({region: 'us-east-1'});
export const handler = async (event, context, callback) => {
  const response = await sqsClient.send(new SendMessageCommand(messageParams));
  console.log(response); // <----- Doesn't reach here
  return callback(null, 'OK'); 
};

IAM Permissions are all correct and the Security Group allows all traffic (When set to a VPC)

So far, to specifically target the timeout problem, I've tried putting the function in a private subnet, public subnet, placing it in no VPC, replacing SDK v3 with aws-sdk v2 via a layer. None of these seem to have any impact on the issue.

I haven't used VPC endpoints yet but I guess that shouldn't be necessary when the function is not connected to a VPC or in a public subnet?

已提問 1 年前檢視次數 310 次
1 個回答
0

Consistent timeouts when trying to call a public API are usually caused by network misconfiguration which prevents the function from being able to reach the internet. In the case of Lambda functions in a VPC, in order to reach the internet they must be configured in a private subnet with a route through a NAT Gateway. See this article for more info on how this should be configured. Alternatively you can add the appropriate VPC endpoints to allow you function to be able to connect with the required APIs privately.

AWS
Kevin_C
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南