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

**URL:** <https://forum.djangoproject.com/t/building-a-django-application-on-aws-with-cloud-development-kit-cdk/2830>\
**Category:** Show & Tell\
**Created:** [June 6, 2020, 5:41pm UTC](https://forum.djangoproject.com/t/building-a-django-application-on-aws-with-cloud-development-kit-cdk/2830 "2020-06-06T17:41:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![briancaffey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/briancaffey/32/414_2.png) [@briancaffey](https://forum.djangoproject.com/u/briancaffey)\
**Post date:** [June 6, 2020, 5:41pm UTC](https://forum.djangoproject.com/t/building-a-django-application-on-aws-with-cloud-development-kit-cdk/2830/1 "2020-06-06T17:41:44Z")

</div>

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/](https://verbose-equals-true.gitlab.io/django-postgres-vue-gitlab-ecs/)  
Repo: [https://gitlab.com/verbose-equals-true/django-postgres-vue-gitlab-ecs](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.

---

<div class="post-metadata">

**Author:** ![briancaffey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/briancaffey/32/414_2.png) [@briancaffey](https://forum.djangoproject.com/u/briancaffey)\
**Post date:** [June 21, 2020, 12:54am UTC](https://forum.djangoproject.com/t/building-a-django-application-on-aws-with-cloud-development-kit-cdk/2830/2 "2020-06-21T00:54:08Z")

</div>

![architecture](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/1/18e6da8083af0c146b37505e0a272330b2937343.jpeg)

Updating this post with an architecture diagram I made using [draw.io](http://draw.io).

---

<div class="post-metadata">

**Author:** ![mslinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mslinn/32/3572_2.png) [@mslinn](https://forum.djangoproject.com/u/mslinn)\
**Post date:** [April 23, 2021, 7:07pm UTC](https://forum.djangoproject.com/t/building-a-django-application-on-aws-with-cloud-development-kit-cdk/2830/3 "2021-04-23T19:07:56Z")

</div>

> [@briancaffey](#):
>
> CloudFront with 3 origins

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

---

<div class="post-metadata">

**Author:** ![briancaffey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/briancaffey/32/414_2.png) [@briancaffey](https://forum.djangoproject.com/u/briancaffey)\
**Post date:** [May 20, 2021, 4:49pm UTC](https://forum.djangoproject.com/t/building-a-django-application-on-aws-with-cloud-development-kit-cdk/2830/4 "2021-05-20T16:49:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mslinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mslinn/32/3572_2.png) [@mslinn](https://forum.djangoproject.com/u/mslinn)\
**Post date:** [May 20, 2021, 5:11pm UTC](https://forum.djangoproject.com/t/building-a-django-application-on-aws-with-cloud-development-kit-cdk/2830/5 "2021-05-20T17:11:23Z")

</div>

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