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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With