I am new to node.js as well to AWS lambda. Initially, I have installed node.js and run some basic scripts in it. I was trying to consume third party APIS like Google, Youtube, and IMDb, etc. I have written the my logic script on the local machine, It is working perfectly on the local machine, as I did the same thing on in exports.handler
the method is not working and throwing errors.
Here is the logic of the handler function:
var https = require('https');
exports.handler = async(event) => {
return sendRes(200, 'Hello');
};
const sendRes = (status, body) => {
const options = {
hostname: 'api.themoviedb.org',
path: '3/search/movie?query=avengers&page=1&api_key=MY-API-KEY',
method: 'GET',
agent: false
};
console.log(options);
const req = https.request(options, (res) => {
console.log("statusCode: ", res.statusCode);
res.on('data', (d) => {
console.log('here in request');
});
});
};
Basically, on triggering specific event Lamda will consume API and return JSON response. Initially when I trigger this function using Test it throws the following error:
Task timed out after 3.00 seconds
I have tried the following solutions after looking over the internet:
- Increased memory
- Increased execution time
Can anyone help me with this?
Refereces: