lambda in nodejs code example
Example 1: invoke lambda nodejs
var AWS = require('aws-sdk');
AWS.config.region = 'eu-west-1';
var lambda = new AWS.Lambda();
exports.handler = function(event, context) {
var params = {
FunctionName: 'Lambda_B',
InvocationType: 'RequestResponse',
LogType: 'Tail',
Payload: '{ "name" : "Alex" }'
};
lambda.invoke(params, function(err, data) {
if (err) {
context.fail(err);
} else {
context.succeed('Lambda_B said '+ data.Payload);
}
})
};
Example 2: aws lambda function setup for node js
$ npm install -g serverless
$ serverless create --template aws-nodejs --name candidate
serverless config credentials --provider aws --key <your_access_key_id> --secret <your_access_key_secret>
serverless deploy