PacktPublishing / AWS-CDK-in-Practice

AWS CDK in Practice, published by Packt
MIT License
53 stars 55 forks source link

Chapter 5 - Instructions for `cdk destroy --profile cdk` Do Not Account for `CDK_MODE` Environment Variable Requirement #11

Open jpnws opened 7 months ago

jpnws commented 7 months ago

In Chapter 5, right before the Summary section, the instruction to execute cdk destroy --profile cdk to destroy the CDK stacks does not consider the conditional stack creation based on the CDK_MODE environment variable as implemented in infrastructure/bin/chapter-5.ts. This omission leads to a situation where executing the provided command directly may result in the message "This app contains no stacks," potentially causing a confusion.

The chapter-5.ts script defines stack instantiation conditionally, depending on the value of the CDK_MODE environment variable. Specifically, stacks are only created if CDK_MODE is set to one of the following values: ONLY_DEV, ONLY_PROD, or ONLY_PIPELINE. Without setting this environment variable appropriately, no stacks are instantiated, and thus, the cdk destroy --profile cdk command fails to identify any stacks to destroy.

It would be beneficial for readers if the instructions included a note about the necessity of setting the CDK_MODE environment variable before attempting to destroy stacks. For example, the book could include a revised instruction like:

CDK_MODE=ONLY_PIPELINE cdk destroy --profile cdk

Furthermore, even after destroying the ONLY_PIPELINE, for example, Chapter5Stack-Production stack remains intact in CloudFormation. Executing the command: CDK_MODE=ONLY_PROD cdk destroy --profile cdk doesn't seem to work, probably because the production stack was not deployed directly from the CDK but by the pipeline stack. I'm not sure if the following would be possible but having a cleanup code in the Chapter 5 codebase would've been helpful, so that when we destroy the pipeline stack, all the other stacks could be destroyed as well.