gpt4 book ai didi

amazon-web-services - 堆栈创建卡在 CREATE_IN_PROGRESS 上

转载 作者:行者123 更新时间:2023-12-04 08:06:14 24 4
gpt4 key购买 nike

我一直在尝试使用 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"] }
}
}

最佳答案

由于 lambda 未正确执行对 cloudformation 的回调,您的模板已挂起。

在 SES 回调中,如果发生错误,首先从不发送回调,但除此之外,您首先使用“context.succeed(event);”终止 Lambda然后调用“response.send(event, context, response.SUCCESS);”。

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

您可以使用本网站上的示例作为引用。 aws lambda for cloudformation

关于amazon-web-services - 堆栈创建卡在 CREATE_IN_PROGRESS 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44048645/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com