Skip to content

Using Terraform to provision Amazon’s ECR and ECS to deploy Django Web App Container

Notifications You must be signed in to change notification settings

joelwembo/django-ecs-ecr-terraform

Repository files navigation

django-ecs-ecr-terraform

image

Deploying a large scale django application to aws can be a bit challenging. You can use your Amazon ECR private repositories to host container images and artifacts that your Amazon ECS tasks may pull from.

In this article, we are going to illustrate how to Use Terraform to provision AWS #ecs and ECR to deploy a containerized django Web App.

✅ Article: http://surl.li/rdddq ✅ Source Code: http://surl.li/rdddw

we also created a CI/CD pipeline using Github Actions to deploy the #dockerized django application to ECS. The pipeline will be triggered on every push to the main branch. The pipeline will update newly terraform added resources, build the docker image, push it to #ECR, and update the ECS service with the new image. #docker #aws #terraform #ecr #ecs #loadbalancing #github #terraformcertified #awscloud #awsdevops #django #djangodeveloper

Local test

docker build -t django-ecs-ecr-terraform .

OR

docker-compose down docker-compose build --no-cache docker-compose up

Screenshot 2024-03-02 012830

Deployment to ECR /ECS

After the terraform resources are deployed

Make sure that you have the latest version of the AWS CLI and Docker installed. For more information, see Getting Started with Amazon ECR . Use the following steps to authenticate and push an image to your repository. For additional registry authentication methods, including the Amazon ECR credential helper, see Registry Authentication . Retrieve an authentication token and authenticate your Docker client to your registry. Use the AWS CLI:

aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin xxxxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com Note: If you receive an error using the AWS CLI, make sure that you have the latest version of the AWS CLI and Docker installed. Build your Docker image using the following command. For information on building a Docker file from scratch see the instructions here . You can skip this step if your image is already built:

docker build -t demo-app-ecr-repo-2 . After the build completes, tag your image so you can push the image to this repository:

docker tag demo-app-ecr-repo-2:latest xxxxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/demo-app-ecr-repo-2:latest Run the following command to push this image to your newly created AWS repository:

docker push xxxxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/demo-app-ecr-repo-2:latest

  1. Authentificate to ECR

aws ecr get-login-password --region ap-southeast-1 --profile default | docker login --username AWS --password-stdin xxxxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com

  1. build the image

docker build -t django-app-ecr-repo .

  1. tag the image

docker tag django-app-ecr-repo:latest xxxxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/django-app-ecr-repo:latest

  1. push the image

docker push xxxxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/django-app-ecr-repo:latest

  1. test locally first

About

Using Terraform to provision Amazon’s ECR and ECS to deploy Django Web App Container

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published