When experimenting with CDK it's possible to deploy a service which is outside of free tier (since nearly all AWS services are supported) and it's useful to be able to delete an entire CDK stack if necessary.
We're going to learn how to delete an entire AWS CDK stack with CDK destroy command.
Instructor: [0:03] At some point, we may decide that we would like to delete our stack entirely. For instance, we would like to migrate it to a different region. Maybe we cannot afford our infrastructure or maybe we just want to delete the app.
[0:12] Given the amount of resources that we currently have in our stack, I mean, the DynamoDB table or the Lambda functions, API gateways, CloudFront distribution, S3 bucket and so on, it would be very tricky to go into CloudFormation and delete all of them one by one. Luckily, there is a better way of solving that problem.
[0:39] I'm going to open up the terminal and run cdk destroy. I'm going to ask whether I want to delete our entire stack. Yes, this is exactly what I want. This is absolutely fine because with CDK, we have a single place where this infrastructure is defined, which is our TypeScript codebase.
[0:55] If we want to, we can deploy the stack again in the future. Of course, the delete operation can take some time, depending on the number and kind of resources that you have in your stack. If you want, you can actually track the process of deleting your entire stack in the events tab of the CloudFormation console.
[1:13] After some time, we can see that our stack has been successfully deleted. If I go back to CloudFormation console and hit refresh button, we can see that our stack is no longer here.