Infra as code to build/deploy django-wise
projects into AWS using:
- VPC
- RDS (Postgres)
- Elasticache (Redis)
- ECS Fargate
- S3 Bucket for statics
- Datadog for Tracing
- CloudWatch for Logging
- CodeBuild/CodePipeline for Deployments
This project is focused in deployment only. all testing/linting and pre deploy tasks should be managed in another engines, I recommend you Github Actions.
-
A S3 bucket for the pipeline artifacts, necesary to keep the AWS pipeline artifacs
-
A SSL certificate for requiered domains, you'll need move NS domain records to Route53
-
Create user with enough permissions to run CDK tasks, and get his
aws_client_id
andaws_client_secret
The user should be able to execute RDS, Elasticache, S3, VPC, ECS tasks -
Create an s3 bucket for pipeline artifacts and use its name in
cdk.stacks.json
file in theartifact_bucket
key. -
Create the following configuration files and place them in the root of the project.
.env
AWS_DEFAULT_REGION=... AWS_REGION=... AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... AWS_ACCOUNT_ID=...
cdk.stacks.json
[ { "stack_name": "<stack-name>", "kms_key_uuid": "KMS item UUID", "cache_node_type": "AWS Redis node types", "num_cache_nodes": 1, "database_size": "AWS RDS size", "database_name": "anything", "database_username": "something", "database_allocated_storage": 25, "database_encrypted": false, "artifact_bucket": "s3 Bucket name for artifacts", "certificate_key_id": "Certificate manager Item UUID", "repo_owner": "name or organization", "repo_name": "repository", "repo_branch": "something", "dns_name": "main domain", "dns_zone_id": "main domain id in route53", "dns_stack_subdomain": "stack subdomain just the left side", "github_access_token": "Personal access token generate in GitHub", "enable_deploy_approval": false }, {...} ]
This step is different acording your SO. One you have all of this, exec the build command.
make build
-
Check changes
$ make diff STACK=<stack-name>
-
Deploy VPC
$ make deploy STACK=<stack-name>-vpc
-
Deploy Main Stack
$ make deploy STACK=<stack-name>
django-wise
template manages environment variables dynamically using chamber
for this.
To configure chamber
you need to do the following:
- Create a KMS Key (Region could be different) https://console.aws.amazon.com/kms/home?region=us-east-1#/kms/keys/create
- Setup its alias as
parameter_store_key
- Copy its
Key ID
and use it in thecdk.stacks.json
config file forkms_key_uuid
key.
S3
may need a cors
configuration:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
- How to setup domain in
Route53
? - How to setup SSL Certificates in
Certificate Manager
? - How to get github access token?