How to deploy Django applications using Docker Swarm, EC2 and CDK

Last Updated on November 27, 2021

⚠️ This article is a draft and is not yet complete. ⚠️


This article describes how to deploy a Django application on an AWS EC2 instance using docker swarm with a reusable CDK construct.


AWS offers several ways to run application workloads. For containerized workloads, AWS offers Elastic Container Service (ECS) and Elastic Kubernetes Service (EKS). This article explores an alternative approach for running containerized applications using Docker Swarm and EC2 instances.

ECS and EKS application infrastructure can be defined easily with Cloud Development Kit (CDK) constructs that we define. I wanted to learn how to write a CDK construct that can do the following:

  • Build a container image for my Django application
  • Build a container image for my frontend Vue.js application
  • Setup an EC2 instance
  • Install docker and docker-compose on the EC2 instance
  • Start a single-node Docker Swarm cluster
  • Deploy a docker stack that includes all services needed for my Django application
  • Run initial scripts (database migrations and static file collection)

Join my mailing list to get updated whenever I publish a new article.

Thanks for checking out my site!
© 2023 Brian Caffey