小编L.D*_*.D.的帖子

使用Lambda的自定义触发器更新AWS CloudFormation

我和团队成员有一个CloudFormation堆栈,其中包含一个由nodejs支持Lambda的自定义资源.

更新lambda/parameters/trigger后,我们希望Lambda首先删除它所创建的第三方资源,然后根据新参数创建新的资源.

这是lambda的exports.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");
}
Run Code Online (Sandbox Code Playgroud)

我们测试了代码,它适用于CloudFormation中的创建和删除,以及无堆栈模式下的创建,删除和更新(我们设置:event.RequestType = process.env.RequestType和sendResponse不执行通常的CloudFormation响应发布,但只是做了context.done()),但我们似乎无法让它在CloudFormation中更新.我开始认为我们误解了Lambda应该做什么'更新'.

我们以前从未能够看到CloudFormation创建的Lambda函数的CloudWatch日志,这无济于事.

以下是CloudFormation模板的相对部分:

   "ManageThirdPartyResources": {
        "Type": "AWS::Lambda::Function",
        "Properties": {
            "Code": …
Run Code Online (Sandbox Code Playgroud)

lambda amazon-web-services aws-cloudformation

5
推荐指数
1
解决办法
1501
查看次数