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.


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.


Updating this post with an architecture diagram I made using

Configuring CloudFront with 3 origins, nice! Avoids CORS issues, thereby minimizing the HTTP handshake required per request.

1 Like

Yes! That’s the idea! Not absolutely necessary, creating dns records for sub domains might be an easier approach in most cases. But for whatever reason I decided that I wanted everything on the same domain

Subdomains would still require the extra preflight handshakes. Only single-domain distributed systems can avoid the CORS tax.