I have a custom AWS::CloudFormation::Transform which is attached to a Lambda function. On successful responses, as mentioned in the documentation, I'm returning the following:
{
"requestId": requestId, //pulled from the event
"status": "success",
"fragment": value //string value
}
This works fine. However, on an error case, I'm not entirely sure what to do. I know that according to the documentation, I should be returning the same structure but with status set to anything other than "success", and I'm assuming (because I can't seem to find anything to confirm this), the error message in the fragment portion. This is what I return on an error case:
{
"requestId": requestId, //pulled from the event
"status": "failure",
"fragment": err.code //string value of error code
}
However, in my CloudFormation I get the following error:
Transform ############::MyCustomMacro failed without an error message.
I know based on the logs that the err.code has a value, so that's not the issue.
Is there something I'm missing on how to properly return an error to CloudFormation?
You can view logs, such as /var/log/cloud-init. log or /var/log/cfn-init. log , to help you debug the instance launch. You can retrieve the logs by logging in to your instance, but you must disable rollback on failure or else AWS CloudFormation deletes the instance after your stack fails to create.
To check your template file for syntax errors, you can use the aws cloudformation validate-template command. The aws cloudformation validate-template command is designed to check only the syntax of your template.
In the console, select the stack set that contains the stack on which the operation failed. In the Actions menu, choose Edit StackSet details to retry creating or updating stacks. On the Specify template page, to use the same AWS CloudFormation template, keep the default option, Use current template.
CloudFormation will continue to provision the resources until completion or stop on a different failure. Remediate any issues to continue the deployment process. CloudFormation performs the necessary updates before retrying provisioning actions on resources that couldn't be successfully provisioned earlier.
I was facing the same problem, but the following JSON response finally worked for me:
{
"requestId": requestId,
"status": "failure",
"fragment": value,
"errorMessage": customErrorMessage // String value
}
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