Skip to content
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

custom-resources: Configurable physical resource IDs on create failure #28996

Closed
2 tasks
athewsey opened this issue Feb 6, 2024 · 2 comments
Closed
2 tasks
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@athewsey
Copy link

athewsey commented Feb 6, 2024

Describe the feature

Today, when a custom resource managed by aws_cdk.custom_resources.Provider fails to create, the expected pattern seems to be for the user-provided onEvent handler to throw an error and the framework to return a dummy physical resource ID - as shown by this in the logs:

[provider-framework] CREATE failed, responding with a marker physical resource id so that the subsequent DELETE will be ignored

It would be great if there's an alternative way to fail creation but actually specify the PhysicalResourceId, so that during rollback a custom handler can see the physical ID of the part-created resource and clean up properly.

Use Case

I'm migrating SAM-based custom resources into CDK, which manage underlying AWS resources (like SageMaker Studio Domains & Amazon Kendra indexes) that get assigned a unique physical ID on creation that's not predictable from the input arguments.

My Custom Resource does some additional pre- and post-processing around the core AWS resource (otherwise I'd just be using direct constructs...), so it's possible for creation to fail after creating an underlying AWS resource.

As I understand, the standard CloudFormation paradigm for this case is that part-created resources are left as-is, and then the DELETE request issued on rollback should trigger clean-up. For CRs that map pretty closely to one particular AWS Resource, our old SAM-based CRs used the underlying resource ID (e.g. SageMaker Studio Domain ID, Kendra Index ID, etc) as the CR PhysicalResourceId. In vanilla CF / SAM, the handler for the DELETE request issued by stack rollback would have visibility of the PhysicalResourceId returned by the (failed) creation

I'd like my custom resource to clean up these partial items during stack rollback, and (for CRs that map pretty closely to one particular AWS Resource) use that underlying resource ID (e.g. SageMaker Studio Domain ID, Kendra Index ID, etc) as the physical resource ID of the CR.

Proposed Solution

Today, provider framework.ts hard-codes 'SUCCESS' in the CloudFormation result unless the user's Lambda function throws an error.

Instead, we could allow user Lambda responses to override this to 'FAILED' but still return whatever PhysicalResourceId and data were in their payload: Giving user Lambdas which are able to catch and properly handle failures a non-breaking ability to take advantage of this feature.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.126.0

Environment details (OS name and version, etc.)

macOS Sonoma

@athewsey athewsey added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Feb 6, 2024
@github-actions github-actions bot added the @aws-cdk/custom-resources Related to AWS CDK Custom Resources label Feb 6, 2024
@pahud
Copy link
Contributor

pahud commented Feb 8, 2024

Sounds like you have a CR that could not properly clean up created resources on DELETE signal? Can you share a very tiny sample with snippets so we can further help?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 8, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants