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 Answer
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
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions