堆栈创建挂在CREATE_IN_PROGRESS上

时间:2017-05-18 13:07:03

标签: amazon-web-services aws-lambda amazon-cloudformation

我一直在尝试使用lambda支持的自定义资源。我尝试使用自定义资源触发Lambda函数。在堆栈创建时,自定义资源在CREATE_IN_PROGRESS上挂起,但是我能够获取电子邮件,并且在尝试删除堆栈时,它仍然在DELETE_IN_PROGRESS上。

现在我有五个堆栈挂在DELETE_IN_PROGRESS上。创建自定义资源在哪里?

     "SendEmailNotification" : {
        "Type": "AWS::Lambda::Function",
        "Properties": {
            "Handler": "index.handler",
            "Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] },
            "Code": {
                "ZipFile":  { "Fn::Join": ["", [
                    "var aws = require('aws-sdk');\n",
                    "var response = require('cfn-response');",
                    "var ses = new aws.SES({\n",
                    "region:'us-east-1'\n",
                    "});\n",
                    "exports.handler = function(event, context) {\n",
                    "console.log('Incoming: ', event);\n",
                    "var eParams = {\n",
                    "Destination: {\n"  ,
                    {"Fn::Join" : ["",["ToAddresses: ['",{ "Ref" : "EmailId" },"']\n"]]},
                    "},\n",
                    "Message: {\n",
                    "Body: {\n",
                    "Text: {\n",
                    {"Fn::Join" : ["",["Data: '", { "Fn::ImportValue" : "DNSName" },"'\n"]]},
                    "}\n",
                    "},\n",
                    "Subject: {\n",
                    "Data: 'Route53 Hosted Zone'\n",
                    "}\n",
                    "},\n",
                    {"Fn::Join" : ["",["Source: '",{ "Ref" : "EmailId" },"'\n"]]},
                    "};\n",
                    "console.log('SENDING EMAIL');\n",
                    "var email = ses.sendEmail(eParams, function(err, data){\n",
                    "if(err) console.log(err);\n",
                    "else {\n",
                    "console.log('EMAIL SENT');\n",
                    "console.log(data);\n",
                    "console.log('EMAIL: ', email);\n",
                    "context.succeed(event);\n",
                    "response.send(event, context, response.SUCCESS);\n",
                    "}\n",
                    "});\n",
                    "};"
                ]]}
            },
            "Runtime": "nodejs6.10"
        }
    },
    "TestResource": {
        "Type": "Custom::TestResource",
        "Properties": {
            "ServiceToken": { "Fn::GetAtt" : ["SendEmailNotification","Arn"] }
        }
    }

1 个答案:

答案 0 :(得分:1)

你的模板正在挂起,因为lambda没有正确执行回调到cloudformation。

在你的SES回调中,你首先不会在出现错误的情况下发送回调,但除此之外,你首先用" context.succeed(event)终止Lambda;"然后调用" response.send(event,context,response.SUCCESS);"。

为了正确实现,您只需要调用response.send函数。在该函数中,将调用callback.succeed。

您可以使用此网站上的示例作为参考。 aws lambda for cloudformation