jeudi 4 juin 2015

simple node.js example in aws lambda

I am trying to send a simple request with aws lambda.

My module structure is as follows:

mylambda
|-- index.js
|-- node_modules
|   |-- request

I zip the file up and it is uploaded to lambda.

Then I invoke it, and it returns the following error. "errorMessage": "Cannot find module 'index'"

Here is the contents of the 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 the request
    var options = {
        url: 'https://myendpoint',
        method: 'POST',
        headers: headers,
        form: {'payload': {"text":""} }
    }

    // Start the 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 back the first key value
};

Any help is appreciated, Thanks




Aucun commentaire:

Enregistrer un commentaire