amazon web services - simple node.js example in aws lambda -
i trying send simple request aws lambda.
my module structure follows:
mylambda |-- index.js |-- node_modules | |-- request
i zip file , uploaded lambda.
then invoke it, , returns following error. "errormessage": "cannot find module 'index'"
here contents of index.js file
var request = require('request'); exports.handler = function(event, context) { var headers = { 'user-agent': 'super agent/0.0.1', 'content-type': 'application/x-www-form-urlencoded' } // configure request var options = { url: 'https://myendpoint', method: 'post', headers: headers, form: {'payload': {"text":""} } } // start request request(options, function (error, response, body) { if (!error && response.statuscode == 200) { console.log(body) } }) console.log('value1 =', event.key1); context.succeed(event.key1); // echo first key value };
any appreciated, thanks
all working now, had increase timeout(s) seconds in advanced settings, taking longer 3 seconds.
also had ensure node modules correctly installed. had messed request module when trying figure out wrong.
to reinstall module, deleted re-installed request.
- deleted node_modules
npm init
- added dependancies
"request" : "*"
in package.json, npm install
. compressed zip , uploaded, working now. :)
Comments
Post a Comment