Deiv
Deiv

Reputation: 3097

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?

Upvotes: 5

Views: 1848

Answers (2)

raza-zaidi
raza-zaidi

Reputation: 46

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
}

Upvotes: 3

bwest
bwest

Reputation: 9844

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.

Upvotes: 3

Related Questions