Reputation: 12662
I did some clean up in my S3 buckets and deleted S3 bucket with weird names. Now my CDK stacks are in weird states. I have some CDK stacks running.
$cdk ls
shows
LambdaHoroscrape
I destroy the stack with those commands
cdk destroy
cdk destroy LambdaHoroscrape
Are you sure you want to delete: LambdaHoroscrape (y/n)? y
LambdaHoroscrape: destroying...
LambdaHoroscrape: destroyed
However the stack LambdaHoroscrape is still present, cdk ls
confirms it.
How can I properly delete this CDK stack ?
Context: I wanted to delete the stack because my deployment ( cdk deploy
) showed this cryptic message
[%] fail: No bucket named 'cdktoolkit-stagingbucket-zd83596pa2cm'. Is account xxxxx bootstrapped?
I boostrapped my account with
cdk bootstrap aws://{account_number}/{region}
Others encountered this cryptic error as well https://github.com/aws/aws-cdk/issues/6808
In the end, because of this error and eagerness to destroy the stack, I lost my DynamoDB data collected since 2 weeks.
Upvotes: 15
Views: 47816
Reputation: 654
When destroying a stack, resources may be deleted, retained, or snapshotted according to their deletion policy. By default, most resources will get deleted upon stack deletion, however that’s not the case for all resources. DynamoDB tables will be retained by default. You can specify removalPolicy
if don't want to retain some resource.
const table = new dynamodb.Table(this, "Hits", {
partitionKey: {
name: "path",
type: dynamodb.AttributeType.STRING
},
removalPolicy: cdk.RemovalPolicy.DESTROY
});
Upvotes: 0
Reputation: 11492
The message is caused by the fact that you deleted the CDK asset bucket created during bootstrapping. You'll need to re-bootstrap your environment to deploy there.
As for deleting, CDK deploys cloudformation stacks, so a sure way to delete something is to go to the cloudformation console and delete the stack.
Regarding the stacks still showing up in cdk ls
after destroying - this is working as expected. cdk destroy
does not remove your CDK code that defines the stack. cdk ls
outputs the stacks that are defined by your CDK code and are present in the synthesized CloudFormation template, regardless of whether they're deployed or not.
Upvotes: 28