Monday, August 17, 2015

Invoking AWS Lambda Function with NodeJs

Use AWS-SDK package with your nodejs code

and here is the code

var AWS = require('aws-sdk'); 
 //set the aws region AWS.config.region = 'us-east-X'; 
AWS.config.update({accessKeyId:"********************",  secretAccessKey:"*************************************"}); 
var lambda = new AWS.Lambda({apiVersion: '2015-03-31'});
//sample test data 
var bufferData = {  "mydata":"my text"}; 
var params = {  FunctionName: 'function name', /* required - function name*/  InvocationType: 'RequestResponse',  LogType: 'Tail',  Payload: JSON.stringify(bufferData)}; 
lambda.invoke(params, function(err, data) {  if (err) 
console.log(err, err.stack); 
// an error occurred  else     
// successful response 

No comments: