📝 Pre-requisite:
Create an AWS ECR Repository:
Name the repository: django-app.
Important: Replace 600735812827.dkr.ecr.us-west-1.amazonaws.com in the commands with your own ECR repository URL.
🔧 Steps: 1️) Update the VARIABLES.TF File:
Replace docker_image_url_django with your ECR repository URL. 2) Update IAM Policies:
Modify the policy file paths in both iam.tf and variables.tf files. 3) Log in to AWS ECR:
aws ecr get-login-password --region us-west-1 | docker login --username AWS --password-stdin
- Navigate to the Application Directory:
cd app/
- Build the Docker Image:
docker build -t /django-app:latest .
- Build the Image for amd64 Platform:
docker build --platform=linux/amd64 -t /django-app:latest .
- Push the Docker Image to ECR:
docker push /django-app:latest
- Navigate to the Terraform Directory and Execute Commands:
Generate SSH Key Pair:
ssh-keygen -f california-region-key-pair
Initialize Terraform:
terraform init
Plan the Terraform Deployment:
terraform plan -out terraform.out
Apply the Terraform Plan:
terraform apply "terraform.out"
- Install Required Python Packages:
pip install boto3 click
- Set AWS Environment Variables:
export AWS_ACCESS_KEY_ID="" export AWS_SECRET_ACCESS_KEY="" export AWS_DEFAULT_REGION="us-west-1"
- Deploy the Application:
Navigate to the deploy Folder:
cd deploy/
Run the Deployment Script:
python3 update-ecs.py --cluster=production-cluster --service=production-service
- Clean Up Resources:
Destroy Terraform-managed Infrastructure:
terraform destroy