无法删除定义Lambda支持的自定义资源的CloudFormation堆栈

时间:2016-02-26 05:57:23

标签: node.js amazon-web-services lambda amazon-cloudformation

我使用 NodeJS 创建了 AWS Lambda 函数来创建VPC流日志。每次触摸自定义资源时, AWS CloudFormation 都会触发此 Lambda

我的问题: 当我删除 CloudFormation 堆栈时,Lambda函数不会将正确的响应发送回 CloudFormation ,并且由于堆栈没有被删除,所以它反映了这个错误:

自定义资源无法在预期时间内稳定

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

由于使用lambda函数的自定义资源,我编写了示例脚本,以便将响应恢复为成功 由于我的要求是使用自定义资源创建NAT网关,因此样本删除功能如下

 var deleteflowlogs = function(event, context) {
    var responseData = {};
    if (event.PhysicalResourceId && event.PhysicalResourceId.match(/^nat-/)) {
        console.log("in delete flow logs");
        ec2.deleteFlowLogs({
            FlowLogIds: [event.PhysicalResourceId]
        }, function(err, data) {
            if (err) {
                responseData = {
                    Error: "delete flowlogs failed " + err
                };
                console.log(responseData.Error);
                response.send(event, context, response.FAILED, responseData, event.PhysicalResourceId);
            } else {
                response.send(event, context, response.SUCCESS, {}, event.PhysicalResourceId)
            }
        })
    } else {
        console.log("No valid physical resource id passed to destroy - ignoring " + event.PhysicalResourceId);
        response.send(event, context, response.SUCCESS, responseData, event.PhysicalResourceId);
    }
}
相关问题