Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development

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.

Coding environment

Refer to the following article for environment preparation Procedure for building a CDK environment on Windows (Python) https://qiita.com/toma_shohei/items/985916e1a95ec4c38121

First get an overview

■ 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

CDK (Python) coding preparation

-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.

Folder structure

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 □ ┣ ・ ・ ・

Provisional support (planned to be fixed in the future, solution unknown at present)

When writing! Ref in the parameter, use "\! Ref" Batch conversion "\! Ref" ⇒ "! Ref" of the output yaml. *! GetAtt is the same

CloudFormation execution

・ 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

Frequently viewed documents

・ 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

Task

・ 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

Impressions

・ 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

Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development
Python development server construction procedure (AWS + Anaconda)
Python development environment construction 2020 [From Python installation to poetry introduction]
Procedure to exe python file from Ubunts environment construction
Python3 environment construction (for beginners)
~ Tips for beginners to Python ③ ~
[For beginners] Script within 10 lines (4. Connection from python to sqlite3)
[For beginners] Django -Development environment construction-
Procedure from environment construction to operation test of testinfra, a server environment test tool made by Python
Python techniques for those who want to get rid of beginners
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
[Python] Minutes of study meeting for beginners (7/15)
Python project environment construction procedure (for windows)
Python> Output numbers from 1 to 100, 501 to 600> For csv
Construction of development environment for Choreonoid class
Tips for Python beginners to use the Scikit-image example for themselves 9 Use from C
From re-environment construction of Python to graph drawing (on visual studio code)
Easy-to-understand explanation of Python Web application (Django) even for beginners (1) [Environment construction]
Memo # 4 for Python beginners to read "Detailed Python Grammar"
Data analysis in Python Summary of sources to look at first for beginners
Python for super beginners Python for super beginners # Easy to get angry
[Ansible installation procedure] From installation to execution of playbook
Memo # 3 for Python beginners to read "Detailed Python Grammar"
Memo # 1 for Python beginners to read "Detailed Python Grammar"
~ Tips for Python beginners from Pythonista with love ① ~
Try to calculate RPN in Python (for beginners)
Easy understanding of Python for & arrays (for super beginners)
Memo # 2 for Python beginners to read "Detailed Python Grammar"
Summary of studying Python to use AWS Lambda
Memo # 7 for Python beginners to read "Detailed Python Grammar"
From 0 to Django development environment construction to basic operation
Introduction to Programming (Python) TA Tendency for beginners
From Python environment construction to virtual environment construction with anaconda
Memo # 6 for Python beginners to read "Detailed Python Grammar"
Call Polly from the AWS SDK for Python
How to make Python faster for beginners [numpy]
~ Tips for Python beginners from Pythonista with love ② ~
Memo # 5 for Python beginners to read "Detailed Python Grammar"
Basic story of inheritance in Python (for beginners)
Understand Python for Pepper development. -Introduction to Python Box-
python beginners tried to predict the number of criminals
[For beginners] How to use say command in python!
The wall of changing the Django service from Python 2.7 to Python 3
[For beginners] How to study Python3 data analysis exam
App development to tweet in Python from Visual Studio 2017
Summary of pre-processing practices for Python beginners (Pandas dataframe)
[Python] Local → Procedure for uploading files to S3 (boto3)
Support for Python 2.7 runtime on AWS Lambda (as of 2020.1)
Procedure for building a CDK environment on Windows (Python)
AWS SDK for Python (Boto3) development in Visual Studio 2017
Python # How to check type and type for super beginners
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Python development environment construction
python textbook for beginners
python2.7 development environment construction
AWS CDK with Python
OpenCV for Python beginners
From white mask to monster mask, development description of serverless LINE photo processing application on AWS
[For beginners of competitive pros] Three input methods to remember when starting competitive programming in Python
Python environment construction and SQL execution example to DB and memo of basic processing for statistics 2019