Pete
Pete

Reputation: 1650

Cannot create connection to DynamoDB in Java AWS lambda function

I have a lambda function, which I'm trying to use to connect to a DynamoDB table I have. I'm using this code to establish the connection:

...

context.getLogger().log("Before create client..");

AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.standard()
    .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
    "https://dynamodb.ap-southeast-2.amazonaws.com", "ap-southeast-2")).build();

context.getLogger().log("After create client..");

...

The output I have from the function is as follows:

==================== FUNCTION OUTPUT ====================
{"errorMessage":"2017-07-28T01:11:34.092Z aeee6505-7331-11e7-b28b-db98038611cc Task timed out after 5.00 seconds"}
==================== FUNCTION LOG OUTPUT ====================
START RequestId: aeee6505-7331-11e7-b28b-db98038611cc Version: $LATEST
Before create client..END RequestId: aeee6505-7331-11e7-b28b-db98038611cc
REPORT RequestId: aeee6505-7331-11e7-b28b-db98038611cc  Duration: 5003.51 ms    Billed Duration: 5000 ms    Memory Size: 256 MB Max Memory Used: 62 MB  
2017-07-28T01:11:34.092Z aeee6505-7331-11e7-b28b-db98038611cc Task timed out after 5.00 seconds

As you can see, it times out when trying to build the connection and never prints the second log statement. Is there a reason it would timeout rather than throwing an exception, e.g. if there's an error with the IAM role or something? The dynamoDB region and lambda region are the same (Sydney - ap-southeast-2), so I'd have thought this would work.

The IAM role the lambda function is using has the following permissions:

AmazonDynamoDBReadOnlyAccess

AmazonS3ReadOnlyAccess

AWSLambdaBasicExecutionRole

Upvotes: 1

Views: 776

Answers (2)

Kumaraswamy
Kumaraswamy

Reputation: 11

It's memory issue only..I changed lambda function to 1024MB it start working fine

Upvotes: 1

Pete
Pete

Reputation: 1650

Fixed it.. bumped up the memory of the lambda function to 1024MB. Seriously not sure why that was required given memory used was always around 60-70MB :/

Upvotes: 4

Related Questions