2

I have my Alexa's lambda function on AWS Lambda Console. There I call a web API I created.

If I call my web API on Visual Studio Code, it works great. But if I use Alexa Developer Console to call my web API, it always says:

Error: connect ECONNREFUSED 127.0.0.1:63713

It's because my web API is in localhost? How can I solve this? I'm struggling yet to testing in local with Alexa Developer Console...

My code:

var url = "http://localhost:63713/_apis/v1.0/Car/GetCarById?id=1";

http.get(url, function (res) {
    var webResponseString = '';

    if (res.statusCode != 200) {
        doWebRequestCallBack(new Error("Non 200 Response"), null);
    }

    res.on('data', function (data) {
        webResponseString += data;
    });

    res.on('end', function () {
        var webResponseObject = JSON.parse(webResponseString);
        doWebRequestCallBack(null, webResponseObject);
    });
}).on('error', function (e) {
    doWebRequestCallBack(new Error(e.message), null); // <-- where I recive the error message
});

1 Answer 1

3

localhost always points to the machine the code is running on.

In this case the lambda is running on one of Amazon's machines so the web app you are trying to access will not be there (as it's running on your machine).

You will need to deploy your web app to somewhere public (e.g. a AWS VM or Light sail instance) and update the lambda to point to that location.

1
  • Ok. That confirms my fears. I'll just have to get the unit tests working so I can continue working. Thank you!
    – Ninita
    Oct 31, 2018 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.