Tomas
Tomas

Reputation: 1141

Aws lambda describe instances time out

I have this simple describe instances function that I'm trying to run in nodejs via AWS Lambda:

var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';

exports.handler = function(event, context) {
    console.log("\n\nLoading handler\n\n");
    var ec2 = new AWS.EC2();
    ec2.describeInstances(function(err, data) {
        console.log("\nIn describe instances:\n");
      if (err) {
        console.log(err, err.stack); 
        context.done(null, 'Function Finished from error!');  // an error occurred
      }else {   
        console.log("\n\n" + data + "\n\n");
        context.done(null, 'Function Finished with data!');   // successful response 
      }
    });
};

This does not return me any errors the only output in CloudWatch is this:

2016-03-21T17:01:59.085Z xxxxxxx-xx.... Task timed out after 3.00 seconds

Anyone have any idea what could be the problem?

Upvotes: 15

Views: 7351

Answers (3)

Seung gi Lim
Seung gi Lim

Reputation: 46

Check this: https://medium.com/@philippholly/aws-lambda-enable-outgoing-internet-access-within-vpc-8dd250e11e12#.2sdn5oyd1

If you are in VPC, you can't access Internet anymore!

You should configure NAT to enable outgoing internet access in lambda.

Upvotes: 3

Deepak Singhal
Deepak Singhal

Reputation: 10876

I also faced same issue.. I increased timeout( Lambda --> Configuration --> Advanced Settings) from 3 seconds to 5 seconds and it worked fine.

Upvotes: 11

jp_inc
jp_inc

Reputation: 345

Make sure the execution role has EC2 permissions and try using:

context.fail() or context.succeed()

vs

context.done()

Upvotes: 2

Related Questions