简体   繁体   中英

AWS CloudFormation Transform - How do I properly return an error message?

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?

I've done some digging and there is currently no way to return an error message with a CloudFormation macro failure. You'll have to use the CloudWatch logs for your Lambda function to debug. I've opened a feature request with the CloudFormation team.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM