in Education by
Can you help me out with this program? I am unable to run this code. varx http = require('http'); exports.handler = function(eventa, contextb) { console.log('start request to ' + eventa.url) http.get(eventa.url, function(res) { console.log("Got response: " + res.statusCode); context.succeed(); }).on('error', function(e) { console.log("Got error: " + e.message); context.done(null, 'ERROR'); }); console.log('end request to ' + eventa.url); } Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Here is the working code, you can try this: const http = require('https') exports.handler = async (event) => { return httprequest().then((data) => { const response = { statusCode: 200, body: JSON.stringify(data), }; return response; }); }; function httprequest() { return new Promise((resolve, reject) => { const options = { host: 'jsonplaceholder.typicode.com', path: '/todos', port: 443, method: 'GET' }; const req = http.request(options, (res) => { if (res.statusCode < 200 || res.statusCode >= 300) { return reject(new Error('statusCode=' + res.statusCode)); } var body = []; res.on('data', function(chunk) { body.push(chunk); }); res.on('end', function() { try { body = JSON.parse(Buffer.concat(body).toString()); } catch(e) { reject(e); } resolve(body); }); }); req.on('error', (e) => { reject(e.message); }); // send the request req.end(); }); } Hope this works. Are Interested in learning AWS? Come & join: AWS Online training Want to know more about AWS Lambda, check out:

Related questions

0 votes
    How to rename the AWS Lambda function which I had created for testing purpose? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I have created lambda function on node.js which returns JSON. It connected with API Gateway and worked well ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    When I want to launch some code serverless, I use AWS Lambda. However, this time my deployment package ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    A tried using the AWS CLI for listing the files in the S3 bucket using: aws s3 ls s3://myS3bucket --recursive -- ... How can I do that? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    S3 is a storage facility, EBS is a device, EFS is a file system. Can you please help me in choosing among the three and where Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I am unable to copy some files from a S3 bucket in AWS CLI Adding * to the path is not helping: ... /personalfiles/file* Please help Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Can someone differentiate between EC2 and Elastic Beanstalk? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Could anyone tell me how to get my first AWS job? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    Could someone tell me how to prepare for the AWS interview? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    I tried to follow this tutorial. This is what I did in the console: pip3 install --user --upgrade awscli after ... 's the problem here? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I installed Ubuntu 12.04 on my instance and am trying to install packages using apt-get, but I am getting the ... do I fix this? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I created a new Access Key and configured that in the AWS CLI with aws configure. It created the .ini file in ~/ ... . How to fix this? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Every time I want to config something with AWS I get the following error : "The config profile (myname) ... encrypt my credentials. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Is it possible to get the ARN of an S3 bucket via the AWS command line? I have looked through the documentation ... way to do this. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm having trouble using * in the AWS CLI to select a subset of files from a certain bucket. Adding * to the ... s3://data/2016-08*. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
...