I am trying to write a simple AWS Lambda function to retrieve data from an external public API. I have copied and pasted code from all over the internet without any luck.
I have stripped down the code to be a simple as possible to keep it simple. The public API is : https://swapi.co/api/people/1/
How can I get the data back from the public API?
const https = require('https');
exports.handler = async (event) => {
var options = {
method: 'GET',
host: 'https://swapi.co/api/people/1/',
};
console.log('options', options);
const req = https.request(options, (res) => {
console.log('statusCode: ${res.statusCode}')
console.log(JSON.stringify(res))
});
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
The log file within the AWS editor shows:
START RequestId: 3ba3f23a-11c2-40af-b9e7-0258a6531728 Version: $LATEST
2019-05-27T16:17:44.839Z 3ba3f23a-11c2-40af-b9e7-0258a6531728 INFO options { method: 'GET', host: 'https://swapi.co/api/people/1/' }
END RequestId: 3ba3f23a-11c2-40af-b9e7-0258a6531728
REPORT RequestId: 3ba3f23a-11c2-40af-b9e7-0258a6531728 Duration: 305.90 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 26 MB