There is a slight chance that your book startup didn't work out. Or maybe you created your CDK project just as a learning exercise. Either way, it's best to clean up after yourself in order to not get hit with any surprise charges.
You can easily destroy your stack and its resources from the command line with cdk destroy
. But don't worry. You can easily restore your stack with cdk deploy
. This is the power of infrastructure as code!
Tomasz Łakomy: [0:00] It's possible that our book API startup is not going to be a huge success. As such, we should learn how to delete a CDK stack.
[0:07] In order to delete a CDK stack, run cdk destroy. This is going to ask us if we want to delete the stack. Yes, we want to delete it. This is fine, by the way, because if you want to restore the stack, we simply have to deploy it again. This is going to take a second because it has to delete all the resources in our CloudFormation stack.
[0:25] Now it's gone, but let's double check. I'm going to go to AWS Console and navigate to CloudFormation. It seems that our stack was deleted because it's not here on the list. Suppose we got extra funding and we want to restore our stack. We can run cdk deploy again and this took a second because it had to recreate all the Lambda functions, DynamoDB table and so on.
[0:47] This is the power of CDK or infrastructure as code in general. We are always able to deploy our stack in a different AWS account, in a different region, with no manual steps required because everything is defined in code.