2017-10-08 67 views
0

調用aws lamda函數我試圖根據電子郵件觸發器調用aws lamda函數。我收到了電子郵件觸發器,它觸發了我期望的if語句,但是它不能執行lambda.invoke。如何從另一個

我失蹤了什麼?我得到大部分的日誌報表,但似乎並沒有

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") 
     } 

}; 
+0

這篇文章可能會有所幫助[https://stackoverflow.com/questions/31714788/can-an-aws-lambda-function-call-another](https://stackoverflow。 com/questions/31714788/can-an-aws-lambda-function-call-another) – KKK

+0

您是否碰巧將您的Lambda函數放入您的VPC中?如果是這樣,您需要一個NAT網關才能讓Lambda函數訪問AWS API(以便調用其他函數)。或者只是從VPC中刪除它。如果那不是,那就試着發佈完整的日誌。 –

回答

-2

這聽起來像你想要的功能。他們將讓您鏈不同拉姆達功能整合在一起,做並行的事情,等

0
  1. 保持你的代碼

    `VAR AWS =需要的頂部您的AWS-SDK文件(「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") 
         } 
    
        };