I am running a api on http://localhost:80/api/test, I want to invoke this api from lambda function but I am not sure what plugin or anything I should use to access same.The reason for for doing so is, I want to do testing lambda and api in development phase
Asked
Active
Viewed 4,095 times
3
-
1If the API is running on your development machine, consider moving it to AWS or a dedicated server as well, or else you'll need to get Lambda to connect to your development machine to access the API (not recommended, unless in very early debugging/development) – Technoguyfication Apr 15 '19 at 23:08
-
1a function running out in aws lambda can't access your localhost. You need to put it somewhere publicly accessible. You can make your machine publicly accessible and point it at your IP address but you'll probably find it easier to just use an ec2 instance or something with a development pipeline. If you're developing your api and lambda in parallel and don't want to be constantly pushing to the cloud every update, run your lambda locally as well with something like aws sam – bryan60 Apr 15 '19 at 23:14
-
1check out ngrok, which will proxy traffic from a publicly resolvable domain to your local machine – Catalyst Apr 15 '19 at 23:50
-
Here's a [step-by-step guide](https://medium.com/@alfasin/invoke-api-running-from-aws-lambda-in-nodejs-6d4f1a5463fe) that explains how to Invoke an API running from AWS Lambda in Node – Nir Alfasi Apr 16 '19 at 03:02
1 Answers
3
I used https://ngrok.com/ to solve it.
Below is the command for localhost
https urls. You can replace the port no 3000
with your port no.
ngrok http https://localhost:3000 -host-header="localhost:3000"
Below is my Lambda Function:
var https = require('https');
exports.testJob = (event, context, callback) => {
var params = {
host: "90abcdef.ngrok.io",
path: "/api/test"
};
var req = https.request(params, function(res) {
let data = '';
console.log('STATUS: ' + res.statusCode);
res.setEncoding('utf8');
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
console.log("DONE");
console.log(JSON.parse(data));
});
});
req.end();
};

Anirudh
- 2,767
- 5
- 69
- 119