• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language HCL
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Deploying Django to AWS ECS with Terraform

Deploying Django to AWS ECS with Terraform

Sets up the following AWS infrastructure:

  • Networking:
    • VPC
    • Public and private subnets
    • Routing tables
    • Internet Gateway
    • Key Pairs
  • Security Groups
  • Load Balancers, Listeners, and Target Groups
  • IAM Roles and Policies
  • ECS:
    • Task Definition (with multiple containers)
    • Cluster
    • Service
  • Launch Config and Auto Scaling Group
  • RDS
  • Health Checks and Logs

Want to learn how to build this?

Check out the post.

Want to use this project?

  1. Install Terraform

  2. Sign up for an AWS account

  3. Create two ECR repositories, django-app and nginx.

  4. Fork/Clone

  5. Build the Django and Nginx Docker images and push them up to ECR:

    $ cd app
    $ docker build -t <AWS_ACCOUNT_ID>.dkr.ecr.us-west-1.amazonaws.com/django-app:latest .
    $ docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-west-1.amazonaws.com/django-app:latest
    $ cd ..
    
    $ cd nginx
    $ docker build -t <AWS_ACCOUNT_ID>.dkr.ecr.us-west-1.amazonaws.com/nginx:latest .
    $ docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-west-1.amazonaws.com/nginx:latest
    $ cd ..
  6. Update the variables in terraform/variables.tf.

  7. Set the following environment variables, init Terraform, create the infrastructure:

    $ cd terraform
    $ export AWS_ACCESS_KEY_ID="YOUR_AWS_ACCESS_KEY_ID"
    $ export AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_ACCESS_KEY"
    
    $ terraform init
    $ terraform apply
    $ cd ..
  8. Terraform will output an ALB domain. Create a CNAME record for this domain for the value in the allowed_hosts variable.

  9. Open the EC2 instances overview page in AWS. Use ssh ec2-user@<ip> to connect to the instances until you find one for which docker ps contains the Django container. Run docker exec -it <container ID> python manage.py migrate.

  10. Now you can open https://your.domain.com/admin. Note that http:// won't work.

  11. You can also run the following script to bump the Task Definition and update the Service:

    $ cd deploy
    $ python update-ecs.py --cluster=production-cluster --service=production-service

More Repositories

1

django-on-docker

Dockerizing Django with Postgres, Gunicorn, and Nginx
Python
1,134
star
2

flask-vue-crud

Single Page App with Flask and Vue.js
Vue
808
star
3

fastapi-sqlmodel-alembic

Sample FastAPI project that uses async SQLAlchemy, SQLModel, Postgres, Alembic, and Docker.
Python
467
star
4

fastapi-crud-async

FastAPI CRUD
Python
436
star
5

fastapi-celery

Example of how to handle background processes with FastAPI, Celery, and Docker
Python
382
star
6

flask-vue-kubernetes

Flask + Vue + Postgres + Docker + Kubernetes
JavaScript
348
star
7

flask-on-docker

Flask + Docker
Python
329
star
8

fastapi-vue

Single Page App with FastAPI and Vue.js
Python
253
star
9

fastapi-tdd-docker

Test-Driven Development with FastAPI and Docker
Python
163
star
10

django-celery

Example of how to handle background processes with Django, Celery, and Docker
Python
154
star
11

django-custom-user-model

django custom user model
Python
139
star
12

flask-microservices-users

Python
123
star
13

fastapi-react

Single Page App with FastAPI and React
JavaScript
122
star
14

fastapi-jwt

Secure a FastAPI app by enabling authentication using JSON Web Tokens (JWTs)
Python
116
star
15

fastapi-docker-traefik

FastAPI with Docker and Traefik
Python
105
star
16

spark-kubernetes

spark on kubernetes
Shell
105
star
17

django-on-docker-letsencrypt

Securing a Containerized Django Application with Let's Encrypt
Python
104
star
18

django-celery-beat

Example of how to manage periodic tasks with Django, Celery, and Docker
Python
87
star
19

flask-celery

Example of how to handle background processes with Flask, Celery, and Docker
Python
84
star
20

vault-consul-docker

Vault + Consul + Docker
Dockerfile
84
star
21

flask-htmx-tailwind

Flask + htmx + Tailwind CSS
JavaScript
81
star
22

fastapi-crud-sync

FastAPI CRUD
Python
78
star
23

taxi-react-app

Code for the Taxi React course
JavaScript
73
star
24

django-docker-s3

Django + S3
Python
70
star
25

django-htmx-tailwind

Django + htmx + Tailwind CSS
JavaScript
67
star
26

simple-task-queue

asynchronous task queues using python's multiprocessing library
Python
65
star
27

vault-consul-kubernetes

vault + consul on kubernetes
Shell
59
star
28

django-github-digitalocean

Continuously Deploying Django to DigitalOcean with Docker and GitHub Actions
Python
54
star
29

django-stripe-checkout

Setting up Stripe Checkout with Django
Python
52
star
30

testdriven-app-2.2

Python
51
star
31

fastapi-celery-project

Python
49
star
32

fastapi-ml

deploying an ML model to Heroku with FastAPI
Python
48
star
33

docker-python-devs

Dockerfile
46
star
34

django-docker-traefik

Django with Docker and Traefik
Python
45
star
35

flask-stripe-checkout

Setting up Stripe Checkout with Flask
Python
44
star
36

django-celery-project

The Definitive Guide to Celery and Django
Python
43
star
37

django-aloe-bdd

BDD with Django and Aloe
Python
43
star
38

testdriven-app-2.5

Python
41
star
39

testdriven-app-2.3

Python
40
star
40

flask-spa-auth

Session-based Auth with Flask for Single Page Apps
JavaScript
38
star
41

docker-ci-cache

Speed up your Docker-based builds on CircleCI, GitLab CI/CD, and GitHub Actions with Docker Layer Caching and BuildKit
Python
38
star
42

flask-docker-swarm

Running Flask on Docker Swarm
Python
37
star
43

falcon-celery

Example of how to handle background processes with Falcon, Celery, and Docker
Python
35
star
44

concurrent-web-scraping

Building a Concurrent Web Scraper with Python and Selenium
HTML
35
star
45

selenium-grid-docker-swarm

web scraping in parallel with Selenium Grid and Docker
Python
35
star
46

openfass-node-restful-api

Simple example of an OpenFaaS RESTful API
JavaScript
34
star
47

node-kubernetes

Node + Kubernetes + GKE
JavaScript
34
star
48

spark-docker-swarm

running apache spark with docker swarm
Dockerfile
34
star
49

testdriven-app

Python
34
star
50

cypress-mochawesome-s3

JavaScript
32
star
51

flask-microservices-main

JavaScript
32
star
52

taxi-ng-app

Code repo for Angular Taxi App course
TypeScript
31
star
53

fastapi-tortoise-aerich

Quick example of FastAPI with Tortoise (ORM) and Aerich (for migration support)
Python
31
star
54

openci

A serverless continuous integration system powered by Python, Flask, and OpenFaaS.
Python
30
star
55

django-stripe-connect

stripe connect with django
Python
30
star
56

flask-vue-stripe

Stripe payments with Vue and Flask
Vue
30
star
57

django-channels-example

Introduction to Django Channels
Python
29
star
58

parallel-concurrent-examples-python

examples of parallelism, concurrency, and asyncio in python
Python
28
star
59

selenium-grid-docker-swarm-test

Distribute automated tests with Selenium Grid and Docker Swarm
Python
28
star
60

flask-react-aws

Python
26
star
61

vault-consul-swarm

Deploy Vault and Consul with Docker Swarm
Shell
24
star
62

django-drf-elasticsearch

Django REST Framework and Elasticsearch
Python
23
star
63

testdriven-app-2.4

Python
23
star
64

flask-ses-rq

Send confirmation emails to newly registered users with Flask, Redis Queue, and Amazon SES
Python
23
star
65

taxi-app

Python
21
star
66

django-search

Basic and Full-text Search with Django and Postgres
Python
21
star
67

django-ajax-xhr

Django AJAX and XHR (XMLHttpRequest) examples
Python
19
star
68

microservices

18
star
69

celery-flower-docker

Celery + Flower + Docker + Nginx + Basic Auth
Python
17
star
70

flask-celery-project

Add Celery to a Flask application
Python
17
star
71

flask-microservices-client

JavaScript
16
star
72

django-react-session-auth

Python
15
star
73

vault-consul-flask

Python
14
star
74

cache-django-view

Caching in Django
Python
13
star
75

kubernetes-fabric

Kubernetes on DigitalOcean
Shell
12
star
76

cypress-parallel

JavaScript
12
star
77

fake-token-api

JavaScript
11
star
78

angular-cypress

TypeScript
10
star
79

django-github-linode

Django + Docker + Linode
Python
10
star
80

flask-docker-traefik

Flask with Docker and Traefik
Python
10
star
81

flask-social-auth

Set up social auth with Flask and Flask-Dance.
Python
10
star
82

django-social-auth

Set up social auth with Django and Django Allauth.
Python
9
star
83

masonite-on-docker

Dockerizing Masonite with Postgres, Gunicorn, and Nginx
JavaScript
8
star
84

flask-microservices-eval

Python
7
star
85

flask-microservices-swagger

7
star
86

python-docker-wheel

Python
7
star
87

openfass-code-eval

JavaScript
6
star
88

csrf-example

CSRF Protection in Flask
Python
6
star
89

django-static-media-files

Working with Static and Media Files in Django
Python
6
star
90

django-party

JavaScript
6
star
91

flask-react-cypress

Python
6
star
92

django-performance-testing

automated django performance tests
Python
6
star
93

django-elastic-beanstalk

Django on AWS Elastic Beanstalk
Python
6
star
94

vue-lexer

a Vue lexer for pygments
Python
5
star
95

django-cbv-fbv

Django Class-based vs Function-based Views
Python
5
star
96

google-analytics-stripe-dashboard

Google Analytics + Stripe Dashboard
CSS
5
star
97

fastapi-elastic-beanstalk

FastAPI on AWS Elastic Beanstalk
Python
5
star
98

private-pypi

private pypi server
Python
4
star
99

pytest_for_beginners_test_project

Test project for following the pytest for beginners article.
Python
4
star
100

digitalocean-app-platform-django

Deploying Django to DigitalOcean App Platform
Python
3
star