Last active
May 23, 2022 15:11
-
-
Save amcginlay/18ec1b532f2957187e1ae92ff6ff2e1e to your computer and use it in GitHub Desktop.
CDK Python MVP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -------------------------------- | |
# from standard Cloud9 environment | |
# -------------------------------- | |
which aws cdk | |
npm install --force -g aws-cdk # upgrade | |
python -m pip install aws-cdk-lib | |
cdk doctor # status check | |
mkdir ~/environment/cdk-app && cd $_ | |
cdk init sample-app --language python # apply sample app | |
cdk bootstrap # apply baseline CDK stack | |
cdk synth # emits the synthesized CloudFormation template | |
cdk deploy --require-approval never # deploy this stack (CdkAppStack) to your default AWS account/region | |
cdk ls | |
# ---------------------- | |
# edit cd_app_stack.py, add ',display_name="test"' parameter to the topic and save the file | |
cdk diff # compare deployed stack with current state | |
cdk deploy # create and apply a CloudFormation ChangeSet | |
# ---------------------- | |
cdk destroy cdk-app # delete your stack | |
# done with CDK? | |
pip install botocore boto3 # required to run python script for emptying versioned buckets | |
aws cloudformation delete-stack --stack-name CDKToolkit | |
export BUCKET=$(aws s3 ls | awk '{print $3}' | grep "^cdk-") | |
# python script for emptying versioned buckets | |
python - << EOF | |
import os, boto3 | |
boto3.resource('s3').Bucket(os.getenv('BUCKET')).object_versions.delete() | |
EOF | |
# dispose of empty bucket | |
aws s3 rb s3://${BUCKET} | |
# NOTE: "cdk bootstrap" creates a versioned bucket which can be a be a little "sticky" during deletion/recreation. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment