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

core: Add Stack property for configuring ephemeral Stacks #28281

Open
1 of 2 tasks
hoegertn opened this issue Dec 7, 2023 · 5 comments
Open
1 of 2 tasks

core: Add Stack property for configuring ephemeral Stacks #28281

hoegertn opened this issue Dec 7, 2023 · 5 comments
Labels
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@hoegertn
Copy link
Contributor

hoegertn commented Dec 7, 2023

Describe the feature

Currently, the AWS CDK does not provide a built-in way to configure a Stack as ephemeral. This proposal suggests adding a stack property to the Stack class that allows users to mark a Stack as ephemeral. When a Stack is marked as ephemeral, its deletion policy and the one of all resources created within should be set to Delete by default, instead of the default Retain. This will ensure that when an ephemeral Stack is deleted, all associated resources are also deleted automatically.

Use Case

The ability to create ephemeral Stacks would be beneficial for various scenarios, such as test deployments, feature branches, and integration testing. By marking a Stack as ephemeral, users can easily create instances of their CDK stack for temporary purposes without worrying about manual cleanup. This can greatly improve development workflows and enable faster iteration for developers.

Proposed Solution

To make the configuration of ephemeral Stacks future-proof and allow for variants between deleting everything and retaining everything, it is proposed to add an enumeration property to the Stack class in the AWS CDK. This enumeration property can have different values to specify the desired deletion behavior, such as "DeleteAll" for deleting all resources, "RetainAll" for retaining all resources, and potentially additional options for different deletion policies. By using an enumeration, users can easily configure the desired behavior while providing flexibility for future variants if needed.

When a user sets the deletion policy of a resource manually, it overrides the default deletion policy set for the ephemeral Stack. If a resource's deletion policy is manually set to "Retain", for example, it will not be automatically deleted when the ephemeral Stack is deleted. This can lead to unintended consequences, as the resource may continue to exist and potentially accrue costs even after the ephemeral Stack is deleted. It is important for users to be aware of this and exercise caution when manually setting deletion policies for resources within an ephemeral Stack.

Other Information

Warning

To prevent users from accidentally creating unsafe deployments, it is important to add a warning when using the ephemeral Stack property. The warning should remind users that ephemeral Stacks are meant for temporary use and should not be used for long-term or critical deployments. This will help users make informed decisions and avoid unintended consequences.

Please feel free to provide detailed feedback and comments on this proposal. Your input is highly valued and will play a crucial role in shaping the final outcome. I would greatly appreciate any specific suggestions, concerns, or ideas you may have regarding this proposal. Your perspective and expertise are important in ensuring that this proposal meets all necessary requirements and addresses all relevant aspects. Thank you in advance for taking the time to review and provide your input.

I am willing to implement this proposal and/or create a pull request if it is found useful. Depending on the current process I am also open to creating an RFC for this in the correct place.

Acknowledgements

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

CDK version used

2.x

Environment details (OS name and version, etc.)

all

@hoegertn hoegertn added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 7, 2023
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Dec 7, 2023
@hoegertn
Copy link
Contributor Author

hoegertn commented Dec 7, 2023

@TheRealAmazonKendra as discussed in Las Vegas

@pahud
Copy link
Contributor

pahud commented Dec 7, 2023

Love it! Thank you for the feature request!

related to #28183

@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 Dec 7, 2023
@sakurai-ryo
Copy link
Contributor

I love this idea!

When a user sets the deletion policy of a resource manually, it overrides the default deletion policy set for the ephemeral Stack.

I agree, but I have one concern.
Some resources have default RemovalPolicy set to SNAPSHOT.

cluster.applyRemovalPolicy(props.removalPolicy ?? RemovalPolicy.SNAPSHOT);

In this case, it may be difficult for Aspects( or something) to determine whether the user wants to explicitly set it to SNAPSHOT in the ephemeral stack (DeleteAll) or whether it should be set to DESTROY since the user has not overridden it manually.

Also, in the case of DeleteAll, it would be more convenient for me personally if an option like emptyOnDelete could be enabled!
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html#autodeleteobjects
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.Repository.html#emptyondelete

@hoegertn
Copy link
Contributor Author

I fully agree. That is why I propose this a a top-level feature and not as an aspect. Each L2/L3 should be able to decide what happens on ephemeral stacks and not the author of the aspect.

@am29d
Copy link

am29d commented Dec 19, 2024

I like the idea, there so many cases where stacks pollute the account and you need to clean up logs, buckets, origin policies and more. It'd be great to set a property on a stack level. Developers won't have to worry about deploying demo stacks or PoCs and will know there won't be any resources left that would increase their bill (i.e. CloudWatch logs).

Are there any other solutions right now you can recommend?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

4 participants