Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing in value to an invoked lambda function from node.js function

I have successfully invoked a lambda function from within my node file. It returns 200 and success, but I need to pass in a value to the function I am calling and am unsure how to do that. I am beginning to learn lambda and believe I am not understanding correctly how some things operate. I am attempting to pass in an email address to the lambda function.

function callLambda(){
var AWS = require('aws-sdk');
AWS.config.region = 'us-west-2'

var lambda = new AWS.Lambda();
var params = {
  FunctionName: 'UploadDailyRecords', 
  Payload: '{"client_id" : "[email protected]"}'
};
lambda.invoke(params, function(err, data) {
  if (err) console.log(err, err.stack);
  else     console.log(data);         
});
}
callLambda();

Also, I am unsure of the correct format of how to invoke it from the other function to accept a variable from this invocation. This is the way the invoked lambda is set up on AWS.

exports.handler = function(event, context, callback) {
  get_clients_email();
  callback(null, "completed");
}

Thanks for any help.

like image 204
Mike Avatar asked Apr 12 '17 14:04

Mike


People also ask

When you invoke a lambda function the function is?

When you invoke a function, you can choose to invoke it synchronously or asynchronously. With synchronous invocation, you wait for the function to process the event and return a response. With asynchronous invocation, Lambda queues the event for processing and returns a response immediately.


1 Answers

Everything looks good, you just need to access the payload parameter in your Lambda function now via event.client_id.

like image 144
Mark B Avatar answered Oct 08 '22 10:10

Mark B