简体   繁体   中英

Pass value and trigger lambda Function from another lambda Function

I have a bunch of Lambda functions that all take the same value and processes the value in different ways. What I would like to do instead of sending the value to each lambda and making it an extra task in Zapier. I would like to send the value to one lambda and that one function sends the value to all the other Lambda functions for processing. Thus lessening all amount of task Zapier has to execute.

Actually what you can do is to make one of the Lambda functions create a AWS SNS message; It is going to handle what you post to it and emit a message to the other Lambda function that is listening to AWS SNS

Inside the function of your Lambda 1 (the one that post the message):

var sns = new AWS.SNS({
  region: 'us-east-1'
});

exports.handler = function(event, context, callback) {
  var params = {
    Message: <YOUR_MESSAGE>, /* required */
    Subject: 'STRING_VALUE',
    TopicArn: <SNS_TOPIC_ARN>
  };
  sns.publish(params, (err, data) => {
    if(err) console.log(err, err.stack);
  });
}

and in the other Lambda function that is listening to AWS SNS :

exports.handler = function(event, context, callback) {
  var message = event.Records[0].Sns.Message; /* Here is your message */
}

The best thing of using it, like this, is that you are going to have all your messages in a queue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM