I have been experimenting with lambda backed custom resources.Iam trying to trigger the Lambda function with Custom Resource. On Stack creation, Custom resource is hanging on CREATE_IN_PROGRESS, but Iam able to get the email and also when trying to delete the Stack, it stucking on DELETE_IN_PROGRESS.
Now I have five stacks hanging on DELETE_IN_PROGRESS. Where are the Custom Resources created?
"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"] }
}
}
Your Template is hanging since the lambda does not execute the callback to cloudformation correctly.
In you SES callback, you first never send the callback in case of an error, but apart from that, you first terminate the Lambda with "context.succeed(event);" and afterward call "response.send(event, context, response.SUCCESS);".
For a correct implementation, you just need to call the response.send function. Within that function, the callback.succeed will be call.
You can use the sample on this site as a reference. aws lambda for cloudformation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With