Because I came with almost one infrastructure and had little development experience Here's a summary of what development beginners did and how to build AWS resources using CDK.
Refer to the following article for environment preparation Procedure for building a CDK environment on Windows (Python) https://qiita.com/toma_shohei/items/985916e1a95ec4c38121
■ Outline understanding material https://pages.awscloud.com/rs/112-TZM-766/images/B-3.pdf
◾️ Try WorkShop ・ Workshop (English) https://cdkworkshop.com/30-python.html
・ Workshop (Japanese: download version) http://bit.ly/cdkworkshopjp
-Open Visual Studio Code and open the directory to specify the working directory.
・ Placement of cdk initialization file Execute the following command from the terminal cdk init app --language=python
-Edit requirements.txt (install resources to handle) ======= aws-cdk.core
aws-cdk.aws-autoscaling aws-cdk.aws-ec2 aws-cdk.aws-elasticloadbalancingv2 aws-cdk.aws-rds aws-cdk.aws-ssm aws-cdk.aws-route53
aws-cdk.aws-autoscaling-common ==================== pip install -r requirements.txt
If you can do this, start coding.
At the stage of cdk init, the following folder structure will be created without permission. https://cdkworkshop.com/30-python/20-create-project/300-structure.html
I have introduced pyyaml to separate the parameters from the code. The folder structure will look like the image below.
・ Folder structure image
CDK-WORKSHOP □┣config □┃┣prd □┃┃┣ec2.yaml □┃┃┣vpc.yaml □ ┃┃┣ ・ ・ ・ □┃┗stg □┃□┣ec2.yaml □┃□┣vpc.yaml □ ┃ □ ┣ ・ ・ ・ □┣cdk-workshop_stack.py □ ┣ ・ ・ ・
When writing! Ref in the parameter, use "\! Ref" Batch conversion "\! Ref" ⇒ "! Ref" of the output yaml. *! GetAtt is the same
・ CloudFormation template output cdk synth --version-reporting false --path-metadata false > C:\Users\test\Desktop\test.txt
・ Implementation of the above provisional measures
・ CloudFormation deploy command (until changeset creation) aws cloudformation deploy --stack-name testStack --template-file C:\Users\test\Desktop\test.txt --no-fail-on-empty-changeset --no-execute-changeset
・ Change set confirmation ⇒ execution When you open CloudFormation from the management console Check the change set of the created stack and press Execute if there is no problem
・ AWS CDK Python Reference https://docs.aws.amazon.com/cdk/api/latest/python/index.html
・ Python examples https://github.com/aws-samples/aws-cdk-examples
・ Use of High-level constructs For operation (?) In which a resource to be newly constructed is constructed with code on an existing resource that has already been constructed manually. Only Low-level constructs (library named CfnXXX) are available
・ No test code is applied It is unexamined what to check in the first place
・ About construction with IaC The quality will definitely go up. (I always make a mistake if it is a construction project of a certain scale I did not make a mistake) Once the verification environment is created, the production environment can be created almost by copying, so the reproducibility is quite high.
・ Characteristics of CDK I have experience building AWS with Terraform, but I have the impression that CDK fits in and has fewer points. Since it is a latecomer tool, the interval between version upgrades is short (committed almost every day), There is a risk because the latest version may not be backward compatible, but at the moment there are only a few things that have plagued me.
Recommended Posts