This repository is the first one in our series.
Attention: Remember to clear all resources to avoid unnecessary costs.
- Python 3,7
- virtualenv
- AWS CDK
- Github Actions
- Create virtualenv
venv
- Create and edit
.env
file - Deploy stack staging
- Deploy using cdk
- "Manually" enable EC2 capacity on the cluster
- Deploy stack production
- Deploy using cdk
- "Manually" enable EC2 capacity on the cluster
-
How to Enable Capacity Provider
-
Create a capacity provider:
export ENV=Staging export AWS_REGION=us-west-2 # Get the required cluster values needed when creating the capacity provider export asg_name=$(aws cloudformation describe-stacks --stack-name nlp-infra-${ENV} | jq -r '.Stacks[].Outputs[] | select(.ExportName != null) | select(.ExportName | contains("EC2ASGName"))| .OutputValue') export asg_arn=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names $asg_name | jq .AutoScalingGroups[].AutoScalingGroupARN) export capacity_provider_name=$(echo "EC2$(date +'%s')") # Creating capacity provider aws ecs create-capacity-provider \ --name $capacity_provider_name \ --auto-scaling-group-provider autoScalingGroupArn="$asg_arn",managedScaling=\{status="ENABLED",targetCapacity=80\},managedTerminationProtection="DISABLED" \ --region $AWS_REGION
-
Associate it with the ECS Cluster:
aws ecs put-cluster-capacity-providers \ --cluster container-demo \ --capacity-providers $capacity_provider_name \ --default-capacity-provider-strategy capacityProvider=$capacity_provider_name,weight=1,base=1
-
-
Create and push
new_branch
:Lint
andCDK Diff Staging and Production
-
Pull request to
staging
andmaster
:Lint
andCDK Diff Staging and Production
-
Push to
staging
:DeployStaging
-
Push to
master
:DeployProduction
- Follow the steps below
This is a blank project for Python development with CDK.
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 .env
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
Once the virtualenv is activated, you can install the required dependencies.
pip install -r requirements.txt
At this point you can now synthesize the CloudFormation template for this code.
cdk synth
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
Enjoy!