3

I've written an AWS lambda that makes an https request to an endpoint that triggers a reset password email. When I run my lambda locally, all runs as expected and I get the email in my inbox, however, when I upload my node code and run the lambda in the AWS console, I get the following error at the point of making the post request:

Error: getaddrinfo ENOTFOUND myfakedomain.com myfakedomain.com:443

The function in my lambda making the https request (using the superagent node module) looks like the following:

function resetPassword(intentRequest, callback) {
    const emailAddress = intentRequest.currentIntent.slots.EmailAddress;
    console.log(`emailAddress is: ${emailAddress}`);
        request
        .post('https://myfakedomain.com:443/passwordreset', emailAddress)
        .set({ 'Content-Type': 'text/plain' })
        .end((resp) => {
          console.log('response was: ' + resp);
        });

    callback(close(intentRequest.sessionAttributes, 'Fulfilled',
    { contentType: 'PlainText', content: `Thanks, a reset password link has been sent to ${emailAddress}.` }));
}

Is there any particular reason for this error when running my lambda via AWS? The reset password endpoint is open so that anyone is able to hit it. I've also tried removing the https:// from the beginning of my post request, but no luck. I guess it doesn't help the error logging is pretty minimal too!

Any help would be great, thanks.

deanmau5
  • 861
  • 7
  • 17
  • 27
  • 1
    did you ever figure this out? I am having the same error and my lambda is not running in a VPC so it shouldn't be an internet access problem. When changing the URL to http everything works fine – cdimitroulas Aug 30 '18 at 15:23

1 Answers1

1

By default AWS VPC resources, whether that is an EC2 (server) instance or as in your case a Lambda function, do not have access to the Internet. So if your Lambda function is VPC-based, it needs to be associated with a VPC that has Internet access configured.

If you haven't done this then that is almost certainly your problem.

There are a couple of links below to relevant AWS documentation: http://docs.aws.amazon.com/lambda/latest/dg/vpc.html https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/

P Burke
  • 1,630
  • 2
  • 17
  • 31
  • 2
    This is incorrect. A Lambda function by default CAN access the internet. A Lambda function in a VPC CANNOT access the internet unless using a NAT gateway. – Noel Llevares Dec 22 '17 at 01:43