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

CustomResource update problem #28999

Closed
andreadisimone opened this issue Feb 6, 2024 · 5 comments
Closed

CustomResource update problem #28999

andreadisimone opened this issue Feb 6, 2024 · 5 comments
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. 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 p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@andreadisimone
Copy link

Describe the bug

I have a CustomResource, implementing a Sagemaker StudioLifecycleConfig.
I use a aws_lambda.Function as a handler for the Provider.

The lambda code contains the bash scripts that define the Lifecycle, converts them to base64 and handles the creation/deletion/update of the Lifecycle using boto3 calls. Since Lifecycle are immutable, on update I delete and recreate the existing Lifecycle.

After initial deployment, I change the bash scripts defining the Lifecycle and redeploy.

Expected Behavior

When I change the bash scripts within the lambda, the desired outcome would be that the CustomResource realizes it needs to be updated and triggers the Provider with an Update event.

Current Behavior

No changes are detected.
Is this intended? What is the recommended way to update a CustomResource each time the code underlying its Provider changes?

Reproduction Steps

Can't really past code here. I hope the explanation is clear enough to at least confirm if this behavior is intended, and possibly provide guidance on how to achieve the desired outcome instead.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.115.0

Framework Version

No response

Node.js Version

18.17.1

OS

linux

Language

Python

Language Version

No response

Other information

No response

@andreadisimone andreadisimone added bug This issue is a bug. 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
@andreadisimone
Copy link
Author

An update here, just to help others with the same problem in the future.

After some trial and error, I found out that the CustomResource decides if it needs updating or not only based on its props. Any change in props will trigger an update. Any change in the code backing up the Provider will not. So my solution is to pass the base64 encoding of the bash script in the props, rather than preparing it in the lambda.

I guess now that I know this, the design makes sense. My only suggestion to the developers is maybe to improve the class documentation to add this information.

Unless of course the devs think this is a bug and I am completely misunderstanding the current behavior.

@pahud
Copy link
Contributor

pahud commented Feb 8, 2024

Did you use the custom resource framework to create your own Provider and pass to CustomResource class or you just write your own native lambda function with bash and handle the onCreate/onUpdate/onDelete yourself? Can you share a little bit about your code snippets?

@pahud pahud added p2 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
@andreadisimone
Copy link
Author

andreadisimone commented Feb 9, 2024

@pahud thanks for your reply. on a high level, here is what I do:

on_event=lambda_.Function(self, "a_name", code=lambda_.Code.from_asset("a_path"), **other_args)
on_event.add_to_role_policy(a_policy_statement)

provider = Provider(self, "provider_name", on_event_handler=on_event)

CustomResource(self, "resource_name", service_token=provider.service_token, properties=**props)

if the bash scripts are a string in the lambda code and I change them, the change is not picked up. if I pass them to the props, changes are properly detected.

I just find it a bit strange that changes in the lambda code do not trigger an update. there may be a lot of things happening in boto3 that cannot easily be wrapped in a prop, and maybe on code change one wants the onEvent hook to be reexecuted. The only way to achieve this in my case would be apparently to add a timestamp to the props.

@pahud
Copy link
Contributor

pahud commented Jun 3, 2024

on_event=lambda_.Function(self, "a_name", code=lambda_.Code.from_asset("a_path"), **other_args)

As I didn't see your code I can't see what's going on there but generally, if you change any code lambda uses, CDK would detect that and update the lambda function for you.

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 3, 2024
Copy link

github-actions bot commented Jun 6, 2024

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 Jun 6, 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 bug This issue is a bug. 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 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