aws / aws/aws-cdk

core: Add Stack property for configuring ephemeral Stacks

Open
#28,281 5 comments 5 reactions 0 assignees View on GitHub
@aws-cdk/core effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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

- [X] 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

Contributor guide

Open the contributing guide

Research direction

Start with the Stack class and trace how deletion policies are assigned to resources. Clarify the proposed enumeration, default behavior, manual overrides, and warning requirements before implementation. Done means ephemeral stacks apply the intended deletion behavior consistently while allowing explicit resource policies to take precedence.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.