Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda Timeout when using DynamoDB #1086

Closed
chrisradek opened this issue Aug 3, 2016 · 8 comments
Closed

Lambda Timeout when using DynamoDB #1086

chrisradek opened this issue Aug 3, 2016 · 8 comments
Labels
service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@chrisradek
Copy link
Contributor

Original issue: #862 (comment)
Creating new issue so we don't pollute the conversation in #862.

Hello

Just tried this code with and without the httpOptions

var aws = require('aws-sdk');
var https = require('https');

exports.handler = function(event, context) {
  var dynamo = new aws.DynamoDB({

    region: 'eu-west-1',
    httpOptions: {
      agent: new https.Agent({
        rejectUnauthorized: true,
        keepAlive: false,
        ciphers: 'ALL',
        secureProtocol: 'TLSv1_method'
      })
    }
  });

  dynamo.listTables(function(err, data) {
    console.log('inside listTables');
    if (err)
      console.log(JSON.stringify(err, null, 2));
    else
      console.log(data.TableNames);
  });
};

And I get timeout. No problem locally calling AWS database.

@benoittgt
Can you set maxRetries to 1 or 0? Also, is your Lambda function in the same region as your DynamoDB client? Do you have many tables to list? You could also try limiting the number of tables that get returned by listTables by setting Limit to see if that's the issue.

@benoittgt
Copy link

benoittgt commented Aug 4, 2016

Thanks @chrisradek

I've the lambda locally with this three simple lignes

var aws = require('aws-sdk');
var dynamo = new aws.DynamoDB({
  region: 'eu-west-1',
  maxRetries: 1
});
dynamo.listTables(function(err, data){console.log(data)});
// > { TableNames: [ 'appaloosa' ] }

But on the lambda with the export handler I get the timeout error. I've tried with the context fail and succeed

var aws = require('aws-sdk');

exports.handler = function(event, context) {
  var dynamo = new aws.DynamoDB({
    region: 'eu-west-1',
    maxRetries: 0
  });

  dynamo.listTables(function(err, data) {
    if (err) {
      context.fail(err.stack)
    } else {
      context.succeed('Function Finished! Data :' + data.TableNames);
    }
  });
};
START RequestId: fd43b184-5a0f-11e6-91bb-a5dd7dd469f7 Version: $LATEST
END RequestId: fd43b184-5a0f-11e6-91bb-a5dd7dd469f7
REPORT RequestId: fd43b184-5a0f-11e6-91bb-a5dd7dd469f7  Duration: 12003.64 ms   Billed Duration: 12000 ms   Memory Size: 128 MB Max Memory Used: 24 MB  
2016-08-04T06:52:32.519Z fd43b184-5a0f-11e6-91bb-a5dd7dd469f7 Task timed out after 12.00 seconds

It's a small database that I made for testing. It's the only one dynamodb table.

And then the surprise. I've created a lambda and dynamo table in us-west-2 with this code on a new lambda

var aws = require('aws-sdk');

exports.handler = function(event, context) {
  var dynamo = new aws.DynamoDB({
    region: 'us-west-2',
    maxRetries: 0
  });

  dynamo.listTables(function(err, data) {
    if (err) {
      context.fail(err.stack);
    } else {
      context.succeed('Function Finished! Data :' + data.TableNames);
    }
  });
};

I just changed the region and then
"Function Finished! Data :appaloosa2"

The issue was related not to the region but to VPC. I remove all VPC configuration on eu-west-1 and it's working. Strange I get a timeout an not a VPC error.

But it's fixed.

Thanks @chrisradek for your time. Feel free to close the issue.

@benoittgt
Copy link

It was not easy to setup properly VPC for DynamoDB and lambda. This gist help me.

https://gist.github.com/reggi/dc5f2620b7b4f515e68e46255ac042a7

@pranavram-cn
Copy link

I'm facing a very similar issue, and I suspect it could be related to this one.

I'm trying to access DynamoDB from a Lambda that's inside a VPC, and it times out. Works fine if I remove the VPC, though.

Would appreciate it if you could share what caused this issue and how it was solved.
Thanks

@spbrds
Copy link

spbrds commented Oct 15, 2017

I'm new on AWS and I had a similar issue also, but it was not related with the VPC, tried to follow the tutorial that benoittgt gave, but it didn't work.

The lambda timed out on the instatiation of the DynamoDB Client:
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build(); DynamoDB dynamoDB = new DynamoDB(client);

It turns out that my lambda had only 128 MB of Memory allocated to the lambda. Once I passed it to 512MB it worked.

This guy saved my life:
https://medium.com/@CodingJoe/dealing-with-dynamodb-write-capacity-limits-and-lambda-timeouts-f4e08d9f4b4f

Thanks

@hustshawn
Copy link

hustshawn commented Mar 7, 2018

@spbrds Yes. It works when increase the default memory from 128MB to 256MB, but it is really weird that the log says the Max Memory I have used is just 33MB. Quite annoying and painful with no clue about the lambda Logs.

@whgibbo
Copy link

whgibbo commented Nov 23, 2018

This also helped me.. I have to increase from 128 to 512MB to work with a Java8 Lambda... Again no error that I could see.. Very strange.

@srchase srchase added the service-api This issue is due to a problem in a service API, not the SDK implementation. label Dec 24, 2018
@hdryx
Copy link

hdryx commented Jul 24, 2019

I'm new on AWS and I had a similar issue also, but it was not related with the VPC, tried to follow the tutorial that benoittgt gave, but it didn't work.

The lambda timed out on the instatiation of the DynamoDB Client:
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build(); DynamoDB dynamoDB = new DynamoDB(client);

It turns out that my lambda had only 128 MB of Memory allocated to the lambda. Once I passed it to 512MB it worked.

This guy saved my life:
https://medium.com/@CodingJoe/dealing-with-dynamodb-write-capacity-limits-and-lambda-timeouts-f4e08d9f4b4f

Thanks

Tried that and didn't work for me. Tried to launch the Lambda in a Private Subnet instead of a Public one and it works fine even with 128 MB Memory.
I don't why it's not working when it's launched in a Public Subnet, but that's the trick.

@lock
Copy link

lock bot commented Sep 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

8 participants