What is AWS Cloud Development Kit?
For the existing cdk-sih
CDK project, see:
-
Entrypoint* cdk-sih/app.py file.
-
Source cdk-sih/cdk_sih directory, containing all CDK stack classes.
-
CDK constructs factory class cdk-sih/cdk_sih/constructs/factory.py file.
(*) For the CDK app starting point, search: # ---------- CDK app ----------
This repo is supported by another repo: aws-scripts-examples
Use the convenient cdk-init.sh
shell script:
# To create a CDK project called "cdk-my-project"
./cdk-init.sh cdk-my-project
The cdk.json
file tells the CDK Toolkit how to execute your app.
This project is set up like a standard Python project. The initialization process also creates a virtualenv within this
project, stored under the venv
directory. To create the virtualenv it assumes that there is a python3
(or python
for Windows) executable in your path with access to the venv
package. If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv manually.
To manually create a virtualenv on MacOS and Linux:
$ python3 -m venv venv
After the init process completes and the virtualenv is created, you can use the following step to activate your virtualenv.
$ source venv/bin/activate
If you are a Windows platform, you would activate the virtualenv like this:
% venv\Scripts\activate.bat
Once the virtualenv is activated, you can install the required dependencies.
$ python3 -m pip install -r requirements.txt
At this point you can now synthesize the CloudFormation template for this code.
$ cdk synth
To add additional dependencies, for example other CDK libraries, just add them to your setup.py
file and rerun
the python3 -m pip install -r requirements.txt
command.
cdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation
What is CDK Bootstrapping?
Use the cdk bootstrap
command to bootstrap one or more AWS environments.
cdk bootstrap aws://ACCOUNT-NUMBER-1/REGION-1 aws://ACCOUNT-NUMBER-2/REGION-2 ...
The following examples illustrate bootstrapping of one and two environments, respectively. Note: The aws://
prefix is optional when specifying an environment.
cdk bootstrap aws://123456789123/us-east-1
cdk bootstrap 123456789123/eu-west-2 123456789123/eu-west-1
Use the --verbose
option to show debug logs.
cdk bootstrap --verbose 123456789123/eu-west-2
Use the convenient cdk-deploy-to-*.sh
shell scripts, to run CDK Deploy against your stacks.
See below example usages:
Deploy to: 123456789123
(foobar) account, in the us-east-1
(N. Virginia) region, the
stacks (CdkPypiCloudFrontStack
):
./cdk-deploy-to-sih-N-Virginia.sh CdkPypiCloudFrontStack
Deploy to: 123456789123
(foobar) account, in the eu-west-2
(London) region, the
stacks (CdkLambdaEc2InstanceAutoStack
,CdkCodepipelineCiCdStack
):
./cdk-deploy-to-sih-London.sh CdkLambdaEc2InstanceAutoStack CdkCodepipelineCiCdStack
See pre-push
shell script in hooks/
.
When pushing to the main
branch, a push is successful unless Black formatter returns a non-zero exit code, in which it
will show the diff regarding what Black would change.
To utilise this pre-push git hook, run the following commands in the project root directory:
# Copy all repo git hooks, into the `.git/hooks/` dir.
cp -av hooks/* .git/hooks
# Set all git hooks to executable, if not already set.
chmod +x .git/hooks/*