CI/CD on AWS: Building a Scalable Deployment Pipeline for Node.js Applications

In today’s agile development environment, fast, reliable, and secure software delivery is crucial. CI/CD (Continuous Integration and Continuous Deployment) is the backbone of modern DevOps practices. AWS offers a powerful toolchain to implement CI/CD pipelines with native integrations, automation, and scalability.

In this post, we’ll set up a simple CI/CD pipeline to automatically build, test, and deploy a Node.js application to EC2 using AWS CodePipeline, CodeBuild, and CodeDeploy.


1. Why Use CI/CD on AWS?

Manual deployment processes often lead to:

  • Delays in release cycles

  • Human errors

  • Inconsistent environments

CI/CD enables:

  • Continuous integration of code

  • Automated testing for early bug detection

  • Streamlined deployments to staging or production

AWS Native CI/CD Tools:

ServiceRole in Pipeline
CodeCommitSource code repository
CodeBuildBuild and test automation
CodePipelinePipeline orchestration
CodeDeployApplication deployment

🧩 Use Case Overview: Node.js Microservice Deployment

Let’s assume you have a Node.js application hosted on GitHub. The goal is to automatically deploy updates to an EC2 instance every time code is pushed to the main branch.


Step-by-Step Guide to Setup CI/CD on AWS

1. Connect GitHub Repository to AWS CodePipeline

Ensure your GitHub repository is ready:

bashCopyEditgit remote add origin https://github.com/your-username/your-repo.git

In AWS CodePipeline:

  • Select GitHub (V2) as your source provider

  • Connect to your repository and choose the main branch


2. Create buildspec.yml for CodeBuild

Add a buildspec.yml file in your project root:

yamlCopyEditversion: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 14
    commands:
      - npm install
  build:
    commands:
      - npm test

artifacts:
  files:
    - '**/*'

This config installs dependencies and runs tests. All files will be passed to the next pipeline stage.


3. Create CodeBuild Project

In the AWS Console:

  • Go to CodeBuild → Create Project

  • Select source provider (GitHub or CodePipeline)

  • Configure the environment (use a managed image with Node.js)

  • Reference your buildspec.yml


4. Configure CodePipeline Stages

Set up a three-stage pipeline:

  1. Source – Connect to GitHub repo

  2. Build – Link to your CodeBuild project

  3. Deploy – Use CodeDeploy to push to EC2


5. Set Up CodeDeploy Agent on EC2

Run the following commands on your EC2 instance:

bashCopyEditsudo yum update
sudo yum install -y ruby wget
cd /home/ec2-user
wget https://aws-codedeploy-<region>.s3.<region>.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto

6. Create appspec.yml for CodeDeploy

In your repo, define a deployment process using appspec.yml:

yamlCopyEditversion: 0.0
os: linux
files:
  - source: /
    destination: /home/ec2-user/app

hooks:
  AfterInstall:
    - location: scripts/restart.sh
      timeout: 180

Ensure your restart.sh script starts the Node.js app correctly.


✅ CI/CD Best Practices on AWS

  • Use IAM roles with least privilege for security

  • Enable test coverage and reporting in CodeBuild

  • Add manual approval stages before production deployment

  • Separate pipelines for dev, staging, and prod environments

  • Enable logging and monitoring with CloudWatch


Final Thoughts

Setting up a CI/CD pipeline on AWS may seem daunting initially, but once in place, it brings tremendous speed and reliability to your software delivery lifecycle.

Start with a simple use case, automate smartly, and scale your DevOps practices as your infrastructure grows.

With the right CI/CD setup, your team will ship faster, with fewer bugs, and more confidence.


Want to take it further?

  • Add health checks and rollback strategies

  • Explore Blue/Green deployments with CodeDeploy

  • Integrate AWS Lambda for serverless post-deployment tasks

11
Subscribe to my newsletter

Read articles from Gayatri Didore | DevOps & Cloud Engineer directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Gayatri Didore | DevOps & Cloud Engineer
Gayatri Didore | DevOps & Cloud Engineer

Passionate DevOps & Cloud Engineer with a strong foundation in AWS, CI/CD, Docker, Kubernetes, and Infrastructure as Code. I specialize in automating deployments, securing cloud infrastructure, and improving release pipelines using tools like GitHub Actions, Jenkins, and Terraform. Currently exploring advanced container orchestration and observability. Let’s build faster, smarter, and scalable systems together!