I am using aws serverless mongodb template which works fine with mongodb queries and other local processing I want make http request to get some data for that i tried. http/http/axios/request
But it just returns me following timeout error
{
"message": "Endpoint request timed out"
}
Following is my last tried code.
const util = require('../../lib/util')
// const UserModel = require('../../schema/User');
const fetch = require("node-fetch");
const url = "https://jsonplaceholder.typicode.com/posts/1";
module.exports = async (event) => {
try {
const response = await fetch(url);
const json = await response.json();
console.log(json);
return util.bind(json)
} catch (error) {
return util.bind(error)
}
}
Similarly API sdk's like paypal and razorpay also become unresponsive wile using. is this problem with aws settings or nodejs code?
Thanks in advance.
Above code works fine on serverless offline
As per AWS all the lambdas has only incoming connection. lambda can not call any http for us. for that we need to have NAT Gateway. using NAT Gateway your lambda/serverless will get internet access and it can make outgoing http calls.