
The process starts by containerizing the Django application with a Dockerfile and configuring PostgreSQL on AWS RDS for persistent production data, while S3 handles static assets (CSS, JS) and media files. The Docker image is tested locally, then pushed to Amazon ECR. To streamline automation, buildspec.yml (containing ECR push commands) and appspec.yml (referencing the ECS task definition) are created before uploading the source code to a private GitHub repository integrated with AWS using a Personal Access Token (PAT).
The CI/CD pipeline is divided into two phases. In Phase 1, AWS CodePipeline triggers CodeBuild on each GitHub push. CodeBuild builds the Docker image, pushes it to ECR, and validates the container. Meanwhile, an ECS Fargate cluster is created and integrated with an Application Load Balancer. Two target groups (blue and green) are associated with the ALB, and listeners (HTTP/HTTPS) are configured to forward traffic. A custom domain is purchased via Route 53, with SSL/TLS certificates provisioned using AWS ACM and attached to the ALB, ensuring secure HTTPS connections.
Before deployments, IAM roles for ECS and CodeDeploy are configured, allowing CodeDeploy to manage ECS services. The Blue-Green deployment strategy is implemented by linking the ECS service to two target groups. On each new release, CodeDeploy reroutes traffic from the active (blue) environment to the standby (green) environment, ensuring zero downtime and easy rollback if issues occur. A small workaround was required to correctly register the secondary target group with the ALB to enable traffic forwarding.
In Phase 2, CodePipeline integrates the full workflow: source from GitHub → CodeBuild for container image creation → CodeDeploy for ECS deployment. On redeployment, the ALB seamlessly shifts traffic between blue and green target groups, showcasing automated, zero-downtime deployments. This architecture combines containerization, serverless compute, CI/CD automation, and modern Blue-Green strategies to deliver a robust, scalable, and production-ready Django deployment pipeline.