-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No PhysicalResourceId is generated when FAILED by init_failure() #67
Comments
By the way, I also tried putting the init_failure() function at the global level like the example in the README.md. But same result
|
What you are suggesting has worked for me in the past. I show an example here: #7 (comment). Does it help? I don't know about the helper.init_failure function. I wouldn't call it if there was a failure. I would just raise an exception. I also wouldn't call the bare Try that and you might get the behavior your expect. Example copied from linked comment: @helper.create
def create(event, context):
logger.info("Got Create")
helper.Data.update({"test": "testdata"})
if not helper.Data.get("test"):
helper.PhysicalResourceId = "MyResourceId"
raise ValueError("this error will show in the cloudformation events log and console.")
return "MyResourceId" |
Thank you for responding. I already have decorated create() update() and delete() functions. My full code is example is as below.
I think I saw that before. It worked for you because you added In general scenario, we won't have any codes (other than calling the helper() ) in the However, these don't work if we do it in the My use case is: I need to validate something in the Apparently that's not possible with current code. It must hit one of create/update/delete() in order for it to generate PhysicalResourceId or reuse one if provided. In fact, if you take the Example in https://github.com/aws-cloudformation/custom-resource-helper/blob/main/README.md and raise an Exception in the "try" block (Line 10) instead of "pass" You'll have this exact issue. |
Full example code:
|
When init_failure() function is used to send a failure to Cloudformation, it doesn't generate PhysicalResourceId. Hence, Cloudformation cannot provide a meaningful error message for the failed resource. Instead, it simply says- Invalid PhysicalResourceId.
In Cloudwatch log it shows-
[DEBUG] 2022-08-30T02:26:04.505Z b9753bbc-aa02-4cdd-9ee8-d94cf5d3f54e {"Status": "FAILED", "PhysicalResourceId": "", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/stack-name/guid", "RequestId": "123", "LogicalResourceId": "MyTestResource", "Reason": "An error occurred (InvalidParameter) when calling the RouteTableId operation: Must provide a RouteTableId", "Data": {}, "NoEcho": false}
My code snippet:
I tried adding
helper.PhysicalResourceId = "SomeID"
before the helper() function. But it doesn't make any difference.I guess this line (https://github.com/aws-cloudformation/custom-resource-helper/blob/main/crhelper/resource_helper.py#L121) is resetting it before it sends the response in this line (https://github.com/aws-cloudformation/custom-resource-helper/blob/main/crhelper/resource_helper.py#L135)
The text was updated successfully, but these errors were encountered: