|
1 | | -# CI-CD-Pipeline-for-Dockerized-Web-App-on-AWS-ECS-using-CodePipeline |
| 1 | +# 🚀 AWS CI/CD Deployment – Flask App on ECS with CodePipeline |
| 2 | + |
| 3 | +This project demonstrates how to build and deploy a **Dockerized Flask web application** to **Amazon ECS (Fargate)** using a fully automated **CI/CD pipeline** built with **AWS CodePipeline**, **CodeBuild**, and **CodeDeploy**. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 🔧 Tech Stack |
| 8 | + |
| 9 | +- **Language**: Python 3.11 (Flask 3.0) |
| 10 | +- **Containerization**: Docker |
| 11 | +- **Infrastructure**: |
| 12 | + - Amazon ECS (Fargate) |
| 13 | + - Amazon ECR (Elastic Container Registry) |
| 14 | + - AWS CodePipeline (CI/CD Orchestration) |
| 15 | + - AWS CodeBuild (Image Build & Push) |
| 16 | + - AWS CodeDeploy (Blue/Green ECS Deployment) |
| 17 | + - Amazon S3 (Artifacts) |
| 18 | + - GitHub / CodeCommit (Source Repo) |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 📁 Project Structure |
| 23 | + |
| 24 | +myapp/ |
| 25 | + |
| 26 | +├── app.py |
| 27 | + |
| 28 | +├── Dockerfile |
| 29 | + |
| 30 | +├── requirements.txt |
| 31 | + |
| 32 | +├── buildspec.yml |
| 33 | + |
| 34 | +└── imagedefinitions.json |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## 🚦 CI/CD Pipeline Flow |
| 41 | + |
| 42 | +1. **Code Commit**: |
| 43 | + - Code is pushed to GitHub or AWS CodeCommit. |
| 44 | +2. **CodePipeline Trigger**: |
| 45 | + - Pipeline is automatically triggered. |
| 46 | +3. **CodeBuild Phase**: |
| 47 | + - Builds Docker image from Dockerfile. |
| 48 | + - Tags and pushes image to ECR. |
| 49 | + - Generates `imagedefinitions.json` file. |
| 50 | +4. **CodeDeploy Phase**: |
| 51 | + - ECS Service is updated with new image (zero-downtime Blue/Green). |
| 52 | +5. ✅ **Deployed Flask App** is now live on ECS Fargate! |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## 📦 Requirements |
| 57 | + |
| 58 | +- AWS CLI Configured |
| 59 | +- IAM Roles: |
| 60 | + - CodePipelineRole |
| 61 | + - CodeBuildRole |
| 62 | + - ECS TaskExecutionRole |
| 63 | +- Amazon ECS Cluster & Service created with: |
| 64 | + - Launch type: Fargate |
| 65 | + - Container name: `myapp-container` |
| 66 | +- Amazon ECR Repo created (`myapp`) |
| 67 | +- S3 Bucket for artifacts (optional but recommended) |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## 🔍 Key Files |
| 72 | + |
| 73 | +### `app.py` |
| 74 | +A simple web app using Flask 3.0: |
| 75 | + |
| 76 | +```python |
| 77 | +@app.route("/") |
| 78 | +def index(): |
| 79 | + return "✅ Deployed Flask 3.0 App via AWS ECS + CodePipeline 🚀" |
| 80 | + |
| 81 | +## 🧪 Testing the App |
| 82 | +After successful deployment, access your application via: |
| 83 | + |
| 84 | +Application Load Balancer (ALB) DNS name |
| 85 | + |
| 86 | +OR ECS Task public IP (if configured) |
| 87 | + |
| 88 | +✅ Deployed Flask 3.0 App via AWS ECS + CodePipeline 🚀 |
| 89 | + |
| 90 | + |
| 91 | +## 📈 Optional Enhancements |
| 92 | +Add unit tests to CodeBuild phase |
| 93 | + |
| 94 | +Add CloudWatch Logs for ECS service |
| 95 | + |
| 96 | +Configure Blue/Green Deployment with health checks |
| 97 | + |
| 98 | +Setup GitHub Actions instead of CodeBuild for CI |
| 99 | + |
| 100 | +Add Slack or Email Notification using SNS |
| 101 | + |
| 102 | + |
| 103 | +## 📄 License |
| 104 | +MIT License – free to use and modify. |
| 105 | + |
| 106 | + |
| 107 | +## 👨💻 Author |
| 108 | +Harsh Sonkar |
| 109 | +AWS | Python | DevOps | Full Stack | Data Engineer |
| 110 | + |
| 111 | + |
0 commit comments