Aws lambda 我们可以使用grunt而不是amazon控制台创建lambda函数吗?

Aws lambda 我们可以使用grunt而不是amazon控制台创建lambda函数吗?,aws-lambda,Aws Lambda,我正在创建一个zip文件,以便使用部署到lambda,但在部署到aws lambda时,我需要首先在amazon控制台中创建函数。我们可以使用grunt而不是amazon控制台创建函数吗?谢谢。您可以使用grunt创建函数 使用如下所示的方法 /* This example creates a Lambda function. */ var params = { Code: { }, Description: "", FunctionName: "MyFunction",

我正在创建一个zip文件,以便使用部署到lambda,但在部署到aws lambda时,我需要首先在amazon控制台中创建函数。我们可以使用grunt而不是amazon控制台创建函数吗?谢谢。

您可以使用grunt创建函数

使用如下所示的方法

/* This example creates a Lambda function. */

 var params = {
  Code: {
  }, 
  Description: "", 
  FunctionName: "MyFunction", 
  Handler: "souce_file.handler_name", // is of the form of the name of your source file and then name of your function handler
  MemorySize: 128, 
  Publish: true, 
  Role: "arn:aws:iam::123456789012:role/service-role/role-name", // replace with the actual arn of the execution role you created
  Runtime: "nodejs4.3", 
  Timeout: 15, 
  VpcConfig: {
  }
 };
 lambda.createFunction(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
   /*
   data = {
    CodeSha256: "", 
    CodeSize: 123, 
    Description: "", 
    FunctionArn: "arn:aws:lambda:us-west-2:123456789012:function:MyFunction", 
    FunctionName: "MyFunction", 
    Handler: "source_file.handler_name", 
    LastModified: "2016-11-21T19:49:20.006+0000", 
    MemorySize: 128, 
    Role: "arn:aws:iam::123456789012:role/service-role/role-name", 
    Runtime: "nodejs4.3", 
    Timeout: 123, 
    Version: "1", 
    VpcConfig: {
    }
   }
   */
 });
注意:您可以用代码填充代码参数,或者使用附加属性引用压缩并上载到S3的代码

例如

还要确保向IAM用户授予所需的权限并运行代码

Code: { /* required */
    S3Bucket: 'STRING_VALUE',
    S3Key: 'STRING_VALUE',
    S3ObjectVersion: 'STRING_VALUE',
    ZipFile: new Buffer('...') || 'STRING_VALUE'
  },