0

For some reason, the script that I am running locally does not work when uploaded to aws lambda. What's weird is that I neither get an error message nor a result. The request simply seems to get stuck and times out.

const request = require('request-promise-native');

... async function (username, password) {
  if (await this.login(username, password)) {
    console.log("Logged in") //works locally
    return Promise.resolve();
  } else {
    console.log("Not logged in") // never gets called
  }



Con.prototype.login = async function (username, password) {

  console.log("login")    //gets printed

  return new Promise(resolve => {

    try {

      const ccc0 = this.getCookies()
      console.log("login cookies:", ccc0) //gets printed

      request.post({
        url: `${loginURL}/login`,
        headers: {
          'Content-Type': 'application/json',
          'Cookie': ccc0
        },
        json: { 'username': username, 'password': password },
        resolveWithFullResponse: true
      }).then((loginResult) => {
        console.log("loginResult") //local reaches here, lambda does not
        resolve(true)
      });

      console.log("Check 2") //gets printed

    } catch (e) {
      console.log("Login failed:") //does not get printed
      console.log(e);
      resolve(false)
    }
  });
}

At first I thought of conflicting promises or something in that regard however when even the console.logs get beyond that state, what could possibly make the request get stuck like that?

Unless Lambda functions have firewalls or something like that by default, I haven't set up anything.

user2161301
  • 674
  • 9
  • 22

1 Answers1

0

The issue was setting a VPC having the potential of breaking your internet connection.

https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/

user2161301
  • 674
  • 9
  • 22