{"id":22796388,"url":"https://github.com/atulkamble/ecs-webapp-deployment","last_synced_at":"2026-05-09T06:08:31.799Z","repository":{"id":264986279,"uuid":"862080962","full_name":"atulkamble/ecs-webapp-deployment","owner":"atulkamble","description":"This repository provides a detailed guide and sample code for deploying a containerized web application using Docker, Amazon ECS, and Fargate. It includes steps to build and push a Docker image to Amazon ECR, and deploy it with ECS, along with optional scaling and load balancing setups.","archived":false,"fork":false,"pushed_at":"2024-09-24T16:12:55.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-15T15:42:06.786Z","etag":null,"topics":["autoscaling","aws","containers","docker","ecr","ecs","fargate","nodejs","webapp"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atulkamble.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-24T02:18:04.000Z","updated_at":"2024-09-24T16:23:43.000Z","dependencies_parsed_at":"2024-11-27T06:31:59.654Z","dependency_job_id":null,"html_url":"https://github.com/atulkamble/ecs-webapp-deployment","commit_stats":null,"previous_names":["atulkamble/ecs-webapp-deployment"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/atulkamble/ecs-webapp-deployment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fecs-webapp-deployment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fecs-webapp-deployment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fecs-webapp-deployment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fecs-webapp-deployment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atulkamble","download_url":"https://codeload.github.com/atulkamble/ecs-webapp-deployment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fecs-webapp-deployment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32809149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoscaling","aws","containers","docker","ecr","ecs","fargate","nodejs","webapp"],"created_at":"2024-12-12T05:12:45.345Z","updated_at":"2026-05-09T06:08:31.750Z","avatar_url":"https://github.com/atulkamble.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deploying a web application using containers\n\nstep-by-step guide, along with sample code, for deploying a web application using containers. In this example, we’ll use **Docker** for containerization and **Amazon ECS with Fargate** for deployment. We will also push the Docker image to **Amazon ECR (Elastic Container Registry)**.\n\n### **1. Containerizing the Web Application with Docker**\n\n#### Step 1: Create a Simple Web Application\nCreate a simple Node.js or Python web application as an example.\n\n**Node.js Example** (`app.js`):\n```javascript\nconst express = require('express');\nconst app = express();\n\napp.get('/', (req, res) =\u003e {\n  res.send('Hello World from Docker!');\n});\n\nconst port = process.env.PORT || 3000;\napp.listen(port, () =\u003e {\n  console.log(`App running on port ${port}`);\n});\n```\n\n#### Step 2: Create a Dockerfile\nThis file defines the environment and steps to build the Docker image.\n\n```Dockerfile\n# Use an official Node.js runtime as a parent image\nFROM node:14\n\n# Set the working directory inside the container\nWORKDIR /usr/src/app\n\n# Copy package.json and package-lock.json to install dependencies\nCOPY package*.json ./\n\n# Install dependencies\nRUN npm install\n\n# Copy the rest of the application code to the container\nCOPY . .\n\n# Expose the port your app runs on\nEXPOSE 3000\n\n# Command to run the application\nCMD [ \"node\", \"app.js\" ]\n```\n\n#### Step 3: Build the Docker Image\nBuild the Docker image using the following command:\n\n```bash\ndocker build -t my-web-app .\n```\n\n#### Step 4: Test the Application Locally\nRun the Docker container to verify everything works:\n\n```bash\ndocker run -p 3000:3000 my-web-app\n```\n\n### **2. Push the Docker Image to Amazon ECR**\n\n#### Step 1: Create a Repository in ECR\nCreate a new ECR repository using the AWS Management Console or CLI:\n\n```bash\naws ecr create-repository --repository-name my-web-app\n```\n\n#### Step 2: Authenticate Docker to ECR\nRun the following command to authenticate Docker to your ECR registry (replace `\u003caws-region\u003e` with your region):\n\n```bash\naws ecr get-login-password --region \u003caws-region\u003e | docker login --username AWS --password-stdin \u003caccount-id\u003e.dkr.ecr.\u003caws-region\u003e.amazonaws.com\n```\n\n#### Step 3: Tag and Push the Docker Image\nTag your Docker image to match the ECR repository URI:\n\n```bash\ndocker tag my-web-app:latest \u003caccount-id\u003e.dkr.ecr.\u003caws-region\u003e.amazonaws.com/my-web-app:latest\n```\n\nPush the image to ECR:\n\n```bash\ndocker push \u003caccount-id\u003e.dkr.ecr.\u003caws-region\u003e.amazonaws.com/my-web-app:latest\n```\n\n### **3. Set Up ECS with Fargate for Deployment**\n\n#### Step 1: Create an ECS Cluster\nCreate an ECS cluster that uses Fargate as the launch type:\n\n```bash\naws ecs create-cluster --cluster-name my-ecs-cluster\n```\n\n#### Step 2: Create a Task Definition\nCreate an ECS task definition that specifies the Docker container image, memory, CPU, and networking details.\n\nSample ECS Task Definition (`task-def.json`):\n```json\n{\n  \"family\": \"my-web-app-task\",\n  \"networkMode\": \"awsvpc\",\n  \"executionRoleArn\": \"arn:aws:iam::\u003caccount-id\u003e:role/ecsTaskExecutionRole\",\n  \"containerDefinitions\": [\n    {\n      \"name\": \"my-web-app\",\n      \"image\": \"\u003caccount-id\u003e.dkr.ecr.\u003caws-region\u003e.amazonaws.com/my-web-app:latest\",\n      \"portMappings\": [\n        {\n          \"containerPort\": 3000,\n          \"protocol\": \"tcp\"\n        }\n      ],\n      \"essential\": true\n    }\n  ],\n  \"requiresCompatibilities\": [ \"FARGATE\" ],\n  \"cpu\": \"256\",\n  \"memory\": \"512\"\n}\n```\n\nRegister the task definition:\n\n```bash\naws ecs register-task-definition --cli-input-json file://task-def.json\n```\n\n#### Step 3: Create an ECS Service\nCreate an ECS service to run the task continuously. This service will run on the ECS cluster using Fargate.\n\n```bash\naws ecs create-service \\\n    --cluster my-ecs-cluster \\\n    --service-name my-web-app-service \\\n    --task-definition my-web-app-task \\\n    --desired-count 2 \\\n    --launch-type FARGATE \\\n    --network-configuration \"awsvpcConfiguration={subnets=[subnet-xyz],securityGroups=[sg-xyz],assignPublicIp=ENABLED}\"\n```\n\nMake sure to replace `subnet-xyz` and `sg-xyz` with the appropriate subnet and security group IDs in your AWS VPC.\n\n### **4. Set Up Load Balancer (Optional)**\nTo expose your application publicly, you might want to set up an **Application Load Balancer** (ALB). Here’s how:\n\n#### Step 1: Create an ALB\nCreate a load balancer in the same VPC and subnets as your ECS service.\n\n#### Step 2: Create a Target Group\nCreate a target group for your ECS tasks.\n\n```bash\naws elbv2 create-target-group \\\n    --name my-web-app-targets \\\n    --protocol HTTP \\\n    --port 3000 \\\n    --vpc-id \u003cvpc-id\u003e\n```\n\n#### Step 3: Attach ALB to ECS Service\nUpdate your ECS service to register tasks with the target group:\n\n```bash\naws ecs update-service \\\n    --cluster my-ecs-cluster \\\n    --service my-web-app-service \\\n    --load-balancers targetGroupArn=\u003ctarget-group-arn\u003e,containerName=my-web-app,containerPort=3000\n```\n\n### **5. Monitor and Auto-Scale**\n\n#### Step 1: Set Up CloudWatch Alarms\nSet up CloudWatch alarms to monitor CPU or memory usage. When an alarm is triggered, you can scale the number of ECS tasks automatically.\n\n#### Step 2: Set Up Auto Scaling\nEnable ECS Service Auto Scaling by creating scaling policies that trigger based on CloudWatch metrics (like CPU utilization).\n\n```bash\naws application-autoscaling register-scalable-target \\\n    --service-namespace ecs \\\n    --resource-id service/my-ecs-cluster/my-web-app-service \\\n    --scalable-dimension ecs:service:DesiredCount \\\n    --min-capacity 1 \\\n    --max-capacity 5\n\naws application-autoscaling put-scaling-policy \\\n    --service-namespace ecs \\\n    --scalable-dimension ecs:service:DesiredCount \\\n    --resource-id service/my-ecs-cluster/my-web-app-service \\\n    --policy-name my-scale-out-policy \\\n    --policy-type TargetTrackingScaling \\\n    --target-tracking-scaling-policy-configuration file://scaling-policy.json\n```\n\n### **6. Continuous Deployment (Optional)**\nTo automate future deployments, set up a CI/CD pipeline using tools like **AWS CodePipeline** or **Jenkins** to automatically push new versions of the Docker image to ECR and update your ECS service.\n\n---\n\nThis workflow allows you to deploy a web application using containers, push the image to ECR, and run the app on ECS using Fargate. You can also integrate auto-scaling and monitoring through CloudWatch.\n\nLet me know if you need additional guidance on any specific step!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fecs-webapp-deployment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatulkamble%2Fecs-webapp-deployment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fecs-webapp-deployment/lists"}