Building a Django application on AWS with Cloud Development Kit (CDK)

Hi Django Forum,

I’d like to share an article I wrote (and accompanying GitLab repo) that covers my experience using the AWS Cloud Development Kit (CDK) to build a Django application.

Article: https://verbose-equals-true.gitlab.io/django-postgres-vue-gitlab-ecs/
Repo: https://gitlab.com/verbose-equals-true/django-postgres-vue-gitlab-ecs

CDK is a powerful abstraction over CloudFormation and it is available in a number of languages (I’m using Python, of course!) It not only helps you define AWS infrastructure, but it can also build and publish container images, push files to S3 and makes working with Lambda functions very easy. I struggled with writing CloudFormation, but this tool has removed a lot of the friction and I have been having a lot of fun with it. Is anyone else here using CDK? I would love for any feedback on my article or project if anyone has time to take a look, thank you!

Here are some of the AWS products I’m using in my CDK/Django (+ Vue.js) project:

  • Route53 hosted zone + ACM
  • CloudFront with 3 origin configs: ALB (for Django API), S3 Website (for static Vue.js site), S3 Origin for Django assets
  • Aurora Postgres Serverless database
  • ElastiCache
  • Fargate for running containerized Django workloads (gunicorn/REST Framework API, Django Channels, Celery, management commands, etc.)
  • Autoscaling celery workers with custom CloudWatch metrics and Lambda function (including scaling all the way down to zero during inactivity, configurable per celery queue)

I’m using AWS CDK in a GitLab CI pipeline to practice Infrastructure as Code/GitOps.

2 Likes

Updating this post with an architecture diagram I made using draw.io.