【发布时间】:2017-03-24 14:22:36
【问题描述】:
我和一个团队成员有一个 CloudFormation 堆栈,其中包含一个 nodejs Lambda 支持的自定义资源。
在更新 lambda/parameters/trigger 时,我们希望 Lambda 首先删除它创建的第 3 方资源,然后根据新参数创建新的资源。
这是 lambda 的 export.handler。
if (event.RequestType == "Delete") {
console.log("Request type == Delete")
var successCallback = function(event, context) {
sendResponse(event, context, "SUCCESS");
}
doDeleteThings(event, context, successCallback);
} else if (event.RequestType == "Create") {
console.log("request type == create")
doCreateThings(event, context);
} else if (event.RequestType == "Update") {
console.log("request type == update")
var successCallback = function(event, context) {
doCreateThings(event, context);
}
doDeleteThings(event, context, successCallback);
} else {
sendResponse(event, context, "SUCCESS");
}
我们已经测试了代码,它适用于 CloudFormation 中的创建和删除,以及无堆栈模式下的创建、删除和更新(我们设置:event.RequestType = process.env.RequestType 和 sendResponse 不执行通常的 CloudFormation 响应 POST,但只是执行 context.done()),但我们似乎无法让它在 CloudFormation 中进行更新。我开始认为我们误解了 Lambda 上的“更新”应该做什么。
我们以前从未能够看到 CloudFormation 创建的 Lambda 函数的 CloudWatch 日志,这无济于事。
这是 CloudFormation 模板的相关部分:
"ManageThirdPartyResources": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "<bucketname>",
"S3Key": "<zipname>.zip"
},
"Description": { "Fn::Join": ["", ["Use cloudformation to automatically create third party resources for the ", { "Ref": "ENV" }, "-", { "Ref": "AWS::StackName" }, " environment"]] },
"Environment": {
"Variables": {
<environment variables that will probably be the things changing.>
}
},
"FunctionName": {
"Fn::Join": ["_", [{ "Ref": "AWS::StackName" }, "ManageThirdPartyResources"]]
},
"Handler": "index.handler",
"Role": "<role>",
"Runtime": "nodejs4.3",
"Timeout": 30
}
},
"ThirdPartyResourcesTrigger": {
"Type": "Custom::ThirdPartyResourcesTrigger",
"Properties": {
"ServiceToken": { "Fn::GetAtt": ["ManageThirdPartyResources", "Arn"] }
}
},
谢谢!
【问题讨论】:
标签: amazon-web-services lambda amazon-cloudformation