@aws-community/self-destruct
v1.1.0
Published
Ephemeral Stacks! A CDK Stack and Construct that will self-destruct after a specified time period.
Downloads
6
Readme
Self-Destruct
:warning: This construct is designed to delete your CDK Stack after a specified amount of time! Use at your own risk! :warning:
Blog Post: Say Goodbye to Your CDK Stacks: A Guide to Self-Destruction
This project publishes an npm library that contains a CDK Stack and CDK Construct that will self-destruct the Stack at a defined interval since the last deployment.
The Step Function:
- Lists the current running executions of itself
- Stops old iterations
- Waits for the specified duration
- Deletes the stack after the "wait"
In the event that the CloudFormation stack was already being deleted, it will gracefully exit.
You can use this in your projects in two ways:
- Extending the Stack
- Using the Construct
Extending the Stack
To build this into your stacks... you can simply extend the stack:
export interface MyStackProps extends SelfDestructStackProps {};
export class MyStack extends SelfDestructStack {
constructor(scope: Construct, id: string, props: MyProps) {
super(scope, id, props);
}
}
By default the self destruct construct is DISABLED. You have to explicitly enable it by passing in the selfDestructEnabled: true
. You can also override the duration with the selfDestructDuration
property.
Installing the construct
If instead you want to install this into an existing stack, you can!
export class MyStack {
constructor(scope: Construct, id: string) {
super(scope, id);
new SelfDestructConstruct(this, 'SelfDestruct', {
duration: Duration.days(7), // a duration is required
});
}
}