-1
我正在使用https://github.com/Tim-B/grunt-aws-lambda创建一个用于部署到lambda的zip文件,但是当部署到aws lambda时,我需要先在亚马逊控制台中创建该函数。我们可以使用grunt而不是亚马逊控制台创建一个函数吗?谢谢。我们可以使用grunt而不是亚马逊控制台创建lambda函数吗?
我正在使用https://github.com/Tim-B/grunt-aws-lambda创建一个用于部署到lambda的zip文件,但是当部署到aws lambda时,我需要先在亚马逊控制台中创建该函数。我们可以使用grunt而不是亚马逊控制台创建一个函数吗?谢谢。我们可以使用grunt而不是亚马逊控制台创建lambda函数吗?
您可以使用AWS JavaScript SDK for Lambda从grunt创建函数。
使用createFunction方法如下所示。
/* 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。
E.g.
Code: { /* required */
S3Bucket: 'STRING_VALUE',
S3Key: 'STRING_VALUE',
S3ObjectVersion: 'STRING_VALUE',
ZipFile: new Buffer('...') || 'STRING_VALUE'
},
同时一定要给予必要的许可的IAM用户和setup JavaScript SDK credentials运行代码。