DEV Community

Cover image for How to Build a CI/CD Pipeline with AWS (Step-by-Step Guide)
Emmanuel Mumba
Emmanuel Mumba

Posted on • Originally published at deepdocs.dev

How to Build a CI/CD Pipeline with AWS (Step-by-Step Guide)

Deploying software manually can be painful. You push code, zip files, upload them to a server, restart processes, and cross your fingers hoping nothing breaks. This process is not only slow but also error-prone. A single missed step can take down your production environment.

That’s where CI/CD (Continuous Integration and Continuous Delivery/Deployment) comes in. By automating testing, building, and deployment, CI/CD pipelines let developers ship code quickly and reliably.

Now, you may be asking: “Why should I use AWS for CI/CD when Jenkins, GitHub Actions, or GitLab CI/CD already exist?”

Here’s the difference: AWS gives you everything in one place. Imagine baking a cake. If you had to go to one shop for flour, another for sugar, and another for icing, it would take forever. But if you had a kitchen stocked with all ingredients, you’d bake much faster. AWS is that kitchen it offers source control, build tools, deployment automation, monitoring, and infrastructure-as-code, all integrated in one ecosystem.

👉 If you’re curious how AWS compares to traditional tools, check out our detailed guide on setting up a CI/CD pipeline with Jenkins.

In this guide, I’ll walk you through how to set up a CI/CD pipeline on AWS from scratch, explain the services involved, show you a practical example, and share best practices to avoid common pitfalls.

What is CI/CD on AWS?

CI/CD on AWS means using AWS cloud-native tools to automate the software delivery process from code commit to production deployment.

AWS provides a full toolkit for CI/CD:

  • AWS CodeCommit → Fully managed Git repositories for storing source code.
  • AWS CodeBuild → Compiles, tests, and packages your code.
  • AWS CodeDeploy → Automates deployment to EC2, Lambda, or on-prem servers.
  • AWS CodePipeline → Orchestrates the workflow, connecting all the stages.
  • Amazon CloudWatch → Monitors logs, metrics, and application health.
  • AWS CloudFormation → Manages infrastructure as code (IaC) for consistency.

By combining these services, AWS allows teams to move faster, reduce manual errors, and scale easily.

Components of an AWS CI/CD Pipeline

Here’s a quick breakdown of the stages and tools:

How AWS CI/CD Works

Let’s break down what actually happens inside an AWS CI/CD pipeline. Think of it as a production line for your code: each stage has a clear responsibility, and together they ensure your app ships smoothly.

1. Code is committed → Developers push code to CodeCommit (or GitHub).

Your pipeline starts when you push code. If you use AWS CodeCommit, it’s a fully managed Git repository that lives inside AWS (similar to GitHub or GitLab, but integrated with AWS IAM). Don’t worry if your team already works with GitHub — CodePipeline can connect to external repos too. The key here is that commits act as the trigger to kick off the whole pipeline.

2. Pipeline detects changes → CodePipeline automatically triggers the workflow.

AWS CodePipeline is the orchestration service. It watches your repo and, whenever new commits land, it kicks off the pipeline. Think of it as the conductor in an orchestra — it doesn’t play the instruments itself but tells each one when to start. The cool part? You define stages (build, test, deploy), and CodePipeline makes sure they run in order.

3. Build stage → CodeBuild compiles the app, runs tests, and produces artifacts.

Next up is AWS CodeBuild, the builder. It spins up an isolated container environment, installs dependencies, runs tests, and compiles your code. For a Node.js/React project, this might mean running npm install followed by npm test and then bundling your app with Webpack. The result is an artifact (a zipped build output, Docker image, or Lambda package) that will be deployed in the next stage.

4. Deploy stage → CodeDeploy deploys the artifacts to servers or Lambda.

Now it’s time to release. AWS CodeDeploy handles rolling out your artifacts to their destination. Depending on your setup, this could be:

  • EC2 instances (traditional servers)
  • ECS (containers)
  • AWS Lambda (serverless apps)
  • On-prem servers (yes, CodeDeploy works outside AWS too)

The magic is that CodeDeploy can do rolling updates, blue/green deployments, or canary releases — so you can test safely before sending new code to all users.

5. Monitor & feedback → CloudWatch tracks performance and errors.

A pipeline doesn’t end with deployment. Amazon CloudWatch and AWS CloudTrail step in here to monitor logs, performance metrics, and errors. If something fails (say a test breaks or a deployment crashes), you get immediate feedback in the pipeline dashboard and can roll back changes automatically. This closes the loop and ensures your system is not just shipped, but also stable.

Step-by-Step Guide: Building a CI/CD Pipeline on AWS

Step 1: Set Up IAM Roles

Go to IAM (Identity and Access Management) in AWS Console.

Create roles for EC2 and CodeDeploy.

Attach policies like AmazonS3ReadOnlyAccess and AWSCodeDeployRole.

These roles ensure secure permissions for instances and deployment.

Step 2: Launch an EC2 Instance

Choose an Amazon Linux.

Connect to your instance via SSH.

Update packages:

Step 3: Install Dependencies & CodeDeploy Agent

Install Ruby and wget:

Download and install CodeDeploy agent:

Step 4: Set Up Source Code

You can store your code in CodeCommit or GitHub. If using GitHub:

  • Link GitHub with AWS CodePipeline.
  • Select repo and branch during pipeline setup.

Step 5: Create a Buildspec File

CodeBuild needs a buildspec.yml file in the root of your repo:

This example is for a Node.js app. It installs dependencies, builds the app, and stores artifacts.

Step 6: Configure CodeDeploy

CodeDeploy requires an appspec.yml file:

This tells CodeDeploy where to place files and what scripts to run post-deployment.

Step 7: Create a CodePipeline

  • Go to AWS CodePipeline → Create Pipeline.
  • Add stages: Source → Build → Deploy.
  • Choose CodeCommit/GitHub as the source.
  • Select CodeBuild project for the build stage.
  • Link CodeDeploy app for the deploy stage.

Step 8: Test the Pipeline

Push a change to your repo.

  • CodePipeline detects it.
  • CodeBuild compiles the code.
  • CodeDeploy pushes it to EC2.
  • You can see logs and status in the AWS Console.

Real-World Example: Node.js App Deployment

Let’s say you have a Node.js Express app hosted on EC2.

  1. Push code to GitHub → triggers pipeline.
  2. CodeBuild → runs npm installnpm test, and npm run build.
  3. Artifacts → packaged and stored in S3.
  4. CodeDeploy → copies files to /var/www/html, restarts the app with pm2.
  5. CloudWatch → monitors memory usage and logs.

Within minutes, your new app version is live.

Common Mistakes and Pro Tips

  1. Not Using IAM Properly
  2. Mistake: Over-permissive IAM roles.
  3. Pro Tip: Use least-privilege access policies.
  4. Skipping Tests
  5. Mistake: Only building, not testing.
  6. Pro Tip: Add unit and integration tests in CodeBuild.
  7. Hardcoding Configs
  8. Mistake: Writing DB passwords in code.
  9. Pro Tip: Use AWS Secrets Manager or SSM Parameter Store.
  10. Ignoring Rollbacks
  11. Mistake: No rollback strategy.
  12. Pro Tip: Use CodeDeploy’s automatic rollback.
  13. Not Monitoring Deployments
  14. Mistake: “Ship it and forget it.”
  15. Pro Tip: Set CloudWatch alarms for CPU, memory, and logs.

Best Practices for AWS CI/CD

  • Automate infrastructure with AWS CloudFormation or Terraform.
  • Use immutable deployments (blue-green or canary).
  • Integrate automated testing early in the pipeline.
  • Set up monitoring & alerts with CloudWatch and SNS.
  • Keep pipelines simple start small, expand as needed.

Conclusion

Building a CI/CD pipeline on AWS might seem complex at first, but once you break it down into stages, it’s straightforward. AWS provides all the tools CodeCommit, CodeBuild, CodeDeploy, and CodePipeline working together seamlessly.

With automation, rollbacks, monitoring, and scalability built in, AWS pipelines help you deliver software faster and safer. Whether you’re deploying a simple Node.js app or a large microservices system, AWS has the flexibility to handle it.

The key takeaway: stop deploying manually. Automate with AWS CI/CD and focus more on writing code, less on shipping it.

Top comments (5)

Collapse
 
harutoengineer profile image
Haruto Yamazaki

Super clear explanation, thanks for breaking down CodePipeline vs CodeBuild vs CodeDeploy. I always got confused about which service does what.

Collapse
 
sofiatechflow profile image
Sofia Ivanova

For me GitHub Actions feels way simpler. I don’t see the point of moving everything to CodePipeline.

Collapse
 
tariqdotdev profile image
Tariq Aziz

Exactly. Plus with CodeDeploy you get canary/blue-green deployments out of the box. Harder to do cleanly in Actions without extra scripts.

Collapse
 
tariqdotdev profile image
Tariq Aziz

Does this work well with monorepos? I’ve got multiple services in one repo and worry about triggering unnecessary builds.

Collapse
 
juliacli profile image
Julia Thompson

I’ve been using GitHub Actions + AWS deploy. Curious if CodePipeline really adds anything extra?