Search code examples
javaamazon-web-servicesamazon-s3aws-lambdaaws-java-sdk

Accessing s3 from java aws lambda


I'm trying to list keys on an S3 bucket from an AWS Lambda function written in Java. Running the code locally works fine (with hardcoded credentials).

When running the same Java code in Lambda, it hangs at listObjects

AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials("XXXXXXXXXXXx",
           "XXXXXXXXXXZZZZZZZZZZz"));


ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
        .withBucketName(bucketName)
        .withMaxKeys(10);
ObjectListing objectListing;

do {
    objectListing = s3client.listObjects(listObjectsRequest);

The hardcoded user credentials and the Lambda execution role both have full access to s3.

Why does the S3 access hangs without error? What permission configuration is wrong?

Running something comparable in Lambda with NodeJS works


Solution

  • The solution was to give the Lambda more memory to work with. For most runs Lambda report arround 111 MB for the execution of the simple S3 listObjects command. So 128 MB was not enough, with 512MB it works fine.