admin管理员组文章数量:1435090
My Lambda runs fine with all services except S3. Any action I try to perform, the execution hangs and I get a timeout. For testing purposes, I'm using a default vpc configuration.
I have the S3 full access policy attached to the Lambda's role.
My function:
import AWS from "aws-sdk";
export const handler = async (event) => {
var s3 = new AWS.S3();
try {
var params = {
Bucket: 'bucket-name',
Key: 'original-b31a4e7537250988ddd0a7e6c241c64b.png'
}
let res = await s3.getObject(params).promise();
console.log(res);
} catch (error) {
console.error(error);
}
}
Response:
{
"errorMessage": "2024-11-16T17:53:39.400Z a4412f66-e960-4f0f-ac3d-c1c71e6bc81a Task timed out after 63.07 seconds"
}
My Lambda runs fine with all services except S3. Any action I try to perform, the execution hangs and I get a timeout. For testing purposes, I'm using a default vpc configuration.
I have the S3 full access policy attached to the Lambda's role.
My function:
import AWS from "aws-sdk";
export const handler = async (event) => {
var s3 = new AWS.S3();
try {
var params = {
Bucket: 'bucket-name',
Key: 'original-b31a4e7537250988ddd0a7e6c241c64b.png'
}
let res = await s3.getObject(params).promise();
console.log(res);
} catch (error) {
console.error(error);
}
}
Response:
{
"errorMessage": "2024-11-16T17:53:39.400Z a4412f66-e960-4f0f-ac3d-c1c71e6bc81a Task timed out after 63.07 seconds"
}
Share
Improve this question
edited Nov 18, 2024 at 2:30
Believer
213 bronze badges
asked Nov 16, 2024 at 18:36
Luis GLuis G
153 bronze badges
1
- Is there a particular reason why you have connected your AWS Lambda function to a VPC? If not, then simply disconnect it and it will work fine. If there IS a reason to connect it to the VPC (eg it also needs to access a database in the VPC), then see @fedi's answer below. – John Rotenstein Commented Nov 17, 2024 at 2:08
2 Answers
Reset to default 1You Lambda resides within a VPC, so it doesn't have a direct connection to the internet. and S3 is an external service. Without the internet access, your Lambda hangs becaues it cannot reach S3.
Other service can work out without any issue because AWS offers VPC endpoint, however S3 requires an additional steps if your Lambda resides in the VPC.
To solve this out you need to:
Add an S3 VPC Endpoint
• Create an S3 VPC Endpoint in the VPC where your Lambda function runs.
• This allows your Lambda to connect to S3 privately without needing internet access.
or
Use a NAT Gateway or NAT Instance
• If you want your Lambda to have full internet access, deploy a NAT Gateway or NAT Instance in a public subnet.
• Ensure your Lambda’s private subnet route table points to the NAT gateway for internet traffic.
If your Lambda doesn’t need to access resources within a private VPC (like RDS or private EC2 instances), the simplest fix is to run the Lambda outside the VPC.
Solution: A proxy gateway in the VPC to allow services like S3 to be connected through SDK without using NAT.
本文标签: amazon web servicesTimeout response when trying to use AWS S3 SDK with lambda (Nodejs)Stack Overflow
版权声明:本文标题:amazon web services - Timeout response when trying to use AWS S3 SDK with lambda (Node.js) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745647231a2668208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论