aws-cloudformation / aws-cloudformation/custom-resource-helper

No PhysicalResourceId is generated when FAILED by init_failure()

Open
#67 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
383
Forks
61
PR merge metrics
No merged PRs in 30d

Description

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:

```
helper = CfnResource()

def lambda_handler(event, context):
if some_condition is True:
helper.init_failure(Exception("Test error"))

helper(event, context)
```

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)

Contributor guide

Open the contributing guide

Research direction

Read crhelper/resource_helper.py around lines 121 and 135, then reproduce the failure with the handler shown in the issue. Verify that init_failure() preserves or generates a PhysicalResourceId and that CloudFormation receives a meaningful failed-resource response.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
backend, cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.