Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda Timeout while communicating with S3

Tags:

I'm trying to simply list all the files in an S3 bucket using Lambda

The code looks as follows:

var AWS = require('aws-sdk'); var s3 = new AWS.S3();  exports.handler = (event, context, callback) => {     s3.listObjectsV2({        Bucket: "bucketname",    }, function(err, data) {        console.log("DONE : " + err + " : " + data);          callback(null, 'Hello from Lambda');     }); }; 

Using the above, I never get the "DONE" printed at all. The log doesn't show any information except for the fact that it timed out.

Is there any troubleshooting I could do here? I would've thought that at least the error would've been shown in the "DONE" section.

like image 599
Zeus Avatar asked Aug 15 '16 22:08

Zeus


People also ask

How do I resolve a Lambda timeout issue?

To troubleshoot the retry and timeout issues, first review the logs of the API call to find the problem. Then, change the retry count and timeout settings of the AWS SDK as needed for each use case. To allow enough time for a response to the API call, add time to the Lambda function timeout setting.

Why is my Lambda timing out?

The Lambda timeouts can be caused by not enough memory or processing power of the Lambda itself, or can be caused by other services. The way to find out what is the reason for the timeout, is digging into the Lambda logs and checking the logs of the container that ended with timeout.

What happens if Lambda timeout?

When the specified timeout is reached, Amazon Lambda terminates execution of your Lambda function. As a best practice, you should set the timeout value based on your expected execution time to prevent your function from running longer than intended.

How does Lambda communicate with S3?

Amazon S3 can send an event to a Lambda function when an object is created or deleted. You configure notification settings on a bucket, and grant Amazon S3 permission to invoke a function on the function's resource-based permissions policy.


1 Answers

Thanks to Michael above. The problem was that it was running inside a VPC. If I change it to No VPC, it works correctly. Your solution may be different if you require it to run in a VPC.

like image 109
Zeus Avatar answered Sep 21 '22 06:09

Zeus