Skip to content

Swiggy Clone Blue-Green ECS Deployment

Level:Intermediate
Time:2-3 hours
Cost:medium
Works locally:No
Cloud creds:Yes
Cleanup:Yes
Reviewed:2026-05-30
Validation:npm --prefix Swiggy_clone install --package-lock-only --ignore-scripts

ECS blue-green deployment with buildspec/appspec.

Outcome Passing pipeline run plus scan/deploy evidence
Tools used Node.js, Docker, ECS, CodePipeline, AWS, AWS CodePipeline
Best fit Intermediate - 2-3 hours
Student workstation Repository files CI/CD pipeline AWS account Validation proof
  • Install or review: Node.js, Docker, ECS, CodePipeline, AWS, AWS CodePipeline.
  • Use your own cloud account credentials and keep them out of commits.
  • This project expects cloud resources, so verify budget alerts and cleanup first.
  • Open the safety guide before running commands that create infrastructure.
Cost and credential stance

Cost risk is medium. Cloud target: AWS. Cloud credentials needed: Yes. Always use your own account, never commit secrets, and confirm cleanup before creating paid infrastructure.

Use this flow before you run commands:

  1. Read the cost and credential warning above.
  2. Review the validation, troubleshooting, cleanup, and portfolio proof sections below.
  3. Follow the original project guide preserved near the bottom of this page.
  4. Return to the validation and cleanup checks before you capture portfolio evidence.

Run the project validation command before and after meaningful changes:

Terminal window
npm --prefix Swiggy_clone install --package-lock-only --ignore-scripts
  • Run npm --prefix Swiggy_clone install --package-lock-only --ignore-scripts first so local tooling issues are visible early.
  • If a command fails, check tool versions, working directory, and required environment variables.
  • For cloud failures, confirm account identity, region, quotas, and least-privilege IAM.
  • For pipeline failures, check repository secrets, runner permissions, and pinned action versions.

Cleanup is available or expected for this lab. Use the cleanup or destroy steps in the guide below, then confirm that local clusters, containers, cloud resources, buckets, state files, and CI secrets are no longer active.

  • Validation command output: npm --prefix Swiggy_clone install --package-lock-only --ignore-scripts
  • Screenshot or terminal proof: Passing pipeline run plus scan/deploy evidence
  • Notes explaining what changed, what failed, and how you fixed it
  • Cleanup evidence, especially for cloud or Kubernetes resources

The original README content is preserved here for lab-specific commands and context. Headings are intentionally demoted so the page outline stays focused on the standard lab flow.

External image reference Source image

In the realm of modern software development, DevSecOps practices are gaining prominence for their emphasis on integrating security seamlessly into the software development lifecycle. One critical aspect of this approach is implementing efficient deployment strategies that not only ensure reliability but also maintain security standards. In this blog post, we will delve into the concept of Blue-Green deployment and demonstrate how to apply it to a Swiggy-clone application hosted on AWS ECS (Elastic Container Service) using AWS Code Pipeline.

What is Blue-Green Deployment?
Blue-Green deployment is a technique used to minimize downtime and risk during the release of new versions of an application. In this approach, two identical production environments, termed ‘Blue’ and ‘Green’, are maintained. At any given time, only one environment (e.g., Blue) serves live traffic while the other (e.g., Green) remains idle. When a new version is to be deployed, the new version is deployed to the idle environment (Green). Once the deployment is validated, traffic is seamlessly switched to the updated environment (Green), allowing for quick rollback to the previous version if issues arise.

Setting up AWS ECS for Swiggy-Clone:
To demonstrate Blue-Green deployment, we’ll use AWS ECS to host our Swiggy-clone application. ECS is a highly scalable container orchestration service provided by AWS.

Implementing Blue-Green Deployment with AWS CodePipeline:
AWS CodePipeline is a fully managed continuous integration and continuous delivery (CI/CD) service that automates the build, test, and deployment phases of your release process. Let’s see how to set up a Blue-Green deployment pipeline using AWS CodePipeline:

1. Source Stage: Connect your CodePipeline to your source code repository (e.g., GitHub). Trigger the pipeline when changes are detected in the repository.

2. Build Stage: Use AWS CodeBuild to build your Swiggy-clone Docker image from the source code. Run any necessary tests during this stage.

3. Deploy Stage: Configure AWS CodeDeploy for ECS to manage the deployment of your application to ECS clusters. Here’s where Blue-Green deployment strategy comes into play:

  • A. Define two ECS services: Blue and Green.
  • B. Use CodeDeploy to deploy the new version of your Swiggy-clone application to the Green service.
  • C. After deployment, automate the ALB routing to gradually shift traffic from the Blue service to the Green service based on predefined health checks.
  • D. Monitor the deployment process and rollback automatically if issues occur during the transition.
🛡️ 2026 DevSecOps Enhancements (What You Will Learn)
Section titled “🛡️ 2026 DevSecOps Enhancements (What You Will Learn)”

This repository’s buildspec.yaml and Dockerfile have been heavily refactored from standard CI/CD scripts into a hardened DevSecOps pipeline:

  1. Multi-Stage Container Security: The application’s Dockerfile has been optimized using multi-stage builds. Production images are now devoid of build tooling, and the Node.js application executes safely via the unprivileged node user rather than root.
  2. Automated Vulnerability Scanning: A mandatory Trivy Image Scan gate blocks the AWS CodeBuild pipeline from successfully building if CRITICAL or HIGH vulnerabilities are detected.
  3. Semantic Branch Versioning: CodeBuild dynamically tags the Docker image push with ${CODEBUILD_BUILD_NUMBER}, completely eliminating the fragile latest tag anti-pattern during ECS deployments.
  1. To run Static Code Analysis we need a sonar server.

  2. Create a key-pair for this purpose.
    i. Navigate to key-pairs in AWS Console and click on “Create key- pair”.

External image reference Source image

ii. Provide a name and select key-pair rype as .pem then click on create.
The .pem file will be downloaded to your local.

External image reference Source image

3. Navigate to EC2 console and click on “Launch Instance”.

External image reference Source image

4. Give a name for it.

External image reference Source image

5. Select AMI as “Ubuntu” and instance type as “t2.medium”.

External image reference Source image

6. Under key-pair select the created one.

External image reference Source image

7. Click on “Launch Instance” by leaving other things as default.

External image reference Source image

8.Once the instance is up and running select it and click on “connect”.
You can use EC2 instance connect or SSH with the pem file you downloaded.

External image reference Source image

9. Install docker.

#### Installing Docker
sudo apt update
sudo apt install docker.io -y
sudo usermod -aG docker ubuntu
sudo systemctl restart docker
sudo chmod 777 /var/run/docker.sock
External image reference Source image

10. Run sonarqube as a docker container.

#### Run Docker Container of Sonarqube
#!/bin/bash
docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
External image reference Source image

11. Ensure that port 9000 is opened in security group of that particular instance.

External image reference Source image

12. Access SonarQube on <public_ip>:9000
Username & Password: admin

External image reference Source image
  1. After getting log-in create a custom password.
External image reference Source image

2. Click on “manually” (<>).

External image reference Source image

3. Click on “locally”.

External image reference Source image

4. Provide a name for it.

External image reference Source image

5. Click on “Set Up” .

External image reference Source image

6. Click on “Generate” and create one.

External image reference Source image

7. Then Under code select other and os as linux. Then Copy sonar token.

External image reference Source image

8. In the AWS console search for “Systems Manager” and then “Parameter Store”.

External image reference Source image

9. Click on “create parameter”.

External image reference Source image

9. Give a name for it.
Note: This must be edited in buildspec.yaml file.

External image reference Source image

10. Provide the copied token in the value section.

External image reference Source image

11. Similarly create parameters for Docker Username, Password and URI.

#In my case
Parameter name: /cicd/sonar/sonar-token Value: <sonar_token>
Parameter name: /cicd/docker-credentials/username Value: <docker_username>
Parameter name: /cicd/docker-credentials/password Value: <docker_password>
Parameter name: /cicd/docker-registry/url Value: docker.io

Note: You need to give your Sonar URL and Project Key in buildspec.yaml

  1. Navigate to AWS Codebuild console and click on “create project”.
External image reference Source image

2. Provide a name for it.

External image reference Source image

3. Under source select github as a source provider.

External image reference Source image

4. Select Connect using OAuth.

External image reference Source image

5. After this it will ask for permissions and github login do all the stuff.

External image reference Source image

6. Under GitHub repo, select the one your application code relies.

External image reference Source image

7. Under Environment leave all of them as default.

External image reference Source image

8. Under Buildspec select “Use a buildspec file” and provide the name as “buildspec.yaml”.

External image reference Source image

9. Under Artifacts Use an already created s3 bucket.

External image reference Source image

10. Click on “Update project”.

External image reference Source image

11. In IAM click on the role that the codebuild created.

External image reference Source image

12. Give “AmazonSSMFullAccess” to access the parameters in Systems Manager and “AWSS3FullAccess” to upload the artifacts.

External image reference Source image

13. Click on “Start build”.
Upon successful build it will look like:

External image reference Source image

SonarQube Analysis:

External image reference Source image

Dependency-Check reports:

External image reference Source image

Trivy File Scan:

External image reference Source image

Trivy Image Scan:

External image reference Source image
  1. Navigate to ECS and click on “Create cluster”.
External image reference Source image

2. Provide a name for it.

External image reference Source image

2. Under infrastructure select “Amazon EC2 instances”

External image reference Source image

3. Give OS as Amazon Linux 2 and instance type as “t2.medium”.

External image reference Source image

4. Give Desired Capacity min as 2 and max as 3.

External image reference Source image

5. Under Network settings Select the VPC and the subnets on which instances to be launched.

External image reference Source image

6. Enable the container insights under monitoring and click “create” .

External image reference Source image
  1. In the same ECS console click on “Task Definition” and then “create new task definition”
External image reference Source image

2. Give a name for it and under “infra requirements” select “Amazon EC2 instances”.

External image reference Source image

3. Give the configuration as below.

External image reference Source image

4. Under container provide Name, Image and container port .

External image reference Source image

5. Under monitoring select as below and click “create”.

External image reference Source image
  1. Navigate to EC2 and under Load Balancer click on “Create load balancer”.
External image reference Source image

2. Select “Application Load Balancer”.

External image reference Source image

2. Provide a name for it.

External image reference Source image

3. Under Network mapping select the vpc sand subnets.

External image reference Source image

4. Under Listeners and routing click on “Create target group”.

External image reference Source image

5. Give a target group name.

External image reference Source image

6. Click on “Next”.

External image reference Source image

7. Select the ECS registered instances and give port for them.

External image reference Source image

8. Click on “Create target group”.

External image reference Source image

9. In the Load balancer select the created one.

External image reference Source image

10. Click on “Create load balancer”.

External image reference Source image

11. To access ECS Code Deploy needs a role so let’s create a one.
Navigate to roles in IAM and click on “Create role”.

External image reference Source image

12. Select Use case as “CodeDeploy-ECS”

External image reference Source image

13. Click on “Next”.

External image reference Source image

14. Give a name for it.

External image reference Source image

15. Click on Create.

External image reference Source image
  1. Under Created ECS cluster and Service section click on “create”.
External image reference Source image

2. Opt Compute as “Launch type”.

External image reference Source image

3. Under Deployment config select Family as the created task definition and give it a name.

External image reference Source image

4. Give desired tasks as 1 and Under Deployment options select Deployment type as “Blue/green deployment” then provide service role you created earlier.

External image reference Source image

5. In the Load balancing section select type as ALB and opt the one you have created.

External image reference Source image

6. Use existing Listener and Target group and TG-2 create a one.

External image reference Source image
External image reference Source image

7. Click on “Create”

External image reference Source image

8. Upon Successful service creation it looks like as:

External image reference Source image

9. Navigate to load balancer and copy the DNS name.
Observe that the traffic to routing to target group TG-1.

External image reference Source image

10. Paste it on your favorite browser.
Observe that the tab name is “Swiggy Application”.

External image reference Source image

11. This will also create an application and deployment group under “code deploy” section.

External image reference Source image
External image reference Source image

12. Create a file named “appspec.yaml” and past the below snippet replacing the task definition arn with yours.

version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: "arn:aws:ecs:ap-south-1:<account_id>:task-definition/swiggy:1"
LoadBalancerInfo:
ContainerName: "swiggy"
ContainerPort: 3000
External image reference Source image
  1. Navigate to Code Pipeline in AWS console and click on “create pipeline”.
External image reference Source image

2. Provide a name for it and click on “next”.

External image reference Source image

3. In source stage give GitHub(Version 2) as Source.

External image reference Source image

4. For source code you need to provide access for github so click on “Connect to GitHub”.

External image reference Source image

5. Provide a connection name.

External image reference Source image

6. Click on “Install a new app”.

External image reference Source image

7. Login to GitHub using your credentials.

External image reference Source image

8. Grant access for that particular repo and save it.

External image reference Source image

9. Click on connect.

External image reference Source image

10. Select the repo and the branch. Under trigger type select “No filter”. Click “Next”.

External image reference Source image

11. Under Build stage add provider as “AWS Code Build”.

External image reference Source image

12. Select Project as one created. Click on “next”.

External image reference Source image

13. Under the deploy stage add AWS CodeDeploy as deploy provider.

External image reference Source image

13. Select the application name and deployment group created by the ECS service.

External image reference Source image

14. Review and Click on “create”.

  1. Now make some changes to the application code.

  2. I am doing a change in public/index.html by changing the title.

External image reference Source image

3. Change it as “Swiggy app” and commit to the GitHub.
When the push happens code pipeline triggers automatically with webhook.

External image reference Source image

4. Source and Build took usual time but code deploy took much.

5. Navigate to that deployment.

External image reference Source image

6. If you want both blue and green versions to be running leave it else if you don’t want click on “Terminate original task set”. It tooks less time.

External image reference Source image

7. Upon success code pipeline looks as :

External image reference Source image
External image reference Source image

8. Now navigate to load balancer section and click on the created one.

9. Copy the DNS of that load balancer.

External image reference Source image

Observe that the traffic is routing to TG-2 (Green) instead of TG-1(Blue).

10. Paste that in your favorite browser.

External image reference Source image
External image reference Source image

Observe that the title changed as expected.

  1. Deleted created Code Pipeline.

  2. Delete ECS Cluster.

  3. Delete Created Code Build.

  4. Delete Sonar-Server EC2 Instance.

If you are planning to use this repository for learning, please give it a star. Thanks!

External image reference Source image

[!Note] Join Our Telegram Community || Follow me for more DevOps Content

Use the guide first.

The full learning flow stays on this page. Open GitHub only when a step asks you to inspect code, fork the lab, or download source assets.