简体   繁体   English

如何从另一个调用aws lamda函数

[英]how to invoke an aws lamda function from another

i am trying to invoke an aws lamda function based on an email trigger. 我正在尝试基于电子邮件触发器调用aws lamda函数。 i get the email trigger in and it hits the if statement i expect but then it fails to do the lambda.invoke. 我收到了电子邮件触发器,并且命中了我期望的if语句,但随后却无法执行lambda.invoke。

what am i missing? 我想念什么? i get to most of the log statements but do not seem 我进入大多数日志语句,但似乎没有

exports.handler = function(event, context) {
    var aws = require('aws-sdk');

    var lambda = new aws.Lambda({
        region: 'us-east-1'
    });

    var sesNotification = event.Records[0].ses;
    //console.log("SES Notification:\n", JSON.stringify(sesNotification, null, 2));
    var sub=sesNotification.mail.commonHeaders.subject;
        if(sub){
            if(sub.toLowerCase()=="startpipeline"){
                console.log("Starting Pipeline");
                lambda.invoke({
                              FunctionName: 'StartDevOpsServers',
                              Payload: JSON.stringify(event, null, 2), // pass params
                              InvocationType: 'Event' 
                            }, function(error, data) {
                              if (error) {

                                console.log("error",error,data);
                                context.done('error', error);
                              }
                              if(data.Payload){

                               console.log("succeed",data.Payload);
                               context.succeed(data.Payload)
                              }
                            });

            }else if(sub.toLowerCase()=="stoppipeline"){
                console.log("Stopping Pipeline");
                                lambda.invoke({
                              FunctionName: 'StopDevOpsServers',
                              Payload: JSON.stringify(event, null, 2) // pass params
                            }, function(error, data) {
                              if (error) {
                                context.done('error', error);
                              }
                              if(data.Payload){

                               context.succeed(data.Payload)
                              }
                            });
                    context.succeed();   

            }else{
                console.log('subjectnotRecognized')
            }
        }else{
            console.log("noSubJect")
        }

};
  1. keep your aws-sdk file on top of your code 将aws-sdk文件置于代码之上

    `var aws = require('aws-sdk'); var aws = require('aws-sdk');

     exports.handler = function(event, context) { var lambda = new aws.Lambda({ region: 'us-east-1' }); var sesNotification = event.Records[0].ses; //console.log("SES Notification:\\n", JSON.stringify(sesNotification, null, 2)); var sub=sesNotification.mail.commonHeaders.subject; if(sub){ if(sub.toLowerCase()=="startpipeline"){ console.log("Starting Pipeline"); lambda.invoke({ FunctionName: 'StartDevOpsServers', Payload: JSON.stringify(event, null, 2), // pass params InvocationType: 'Event' }, function(error, data) { if (error) { console.log("error",error,data); context.done('error', error); } if(data.Payload){ console.log("succeed",data.Payload); context.succeed(data.Payload) } }); }else if(sub.toLowerCase()=="stoppipeline"){ console.log("Stopping Pipeline"); lambda.invoke({ FunctionName: 'StopDevOpsServers', Payload: JSON.stringify(event, null, 2) // pass params }, function(error, data) { if (error) { context.done('error', error); } if(data.Payload){ context.succeed(data.Payload) } }); context.succeed(); }else{ console.log('subjectnotRecognized') } }else{ console.log("noSubJect") } }; 

It sounds like you want Step Functions. 听起来像您想要步进功能。 They will allow you to chain different lambda functions together, do things in parallel, etc. 它们将允许您将不同的lambda函数链接在一起,并行执行操作等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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