Set up a fully automated CI/CD pipeline using AWS CodePipeline, CodeBuild, CodeDeploy, EC2, and GitHub. This guide will help you create a zero-touch solution that automates code updates, ensures reliable deployments, and eliminates the need for manual SSH sessions. By the end, you'll have a robust and efficient deployment process that enhances both reliability and speed.
Quick Links
- Overview & Benefits
- Step 1: GitHub Repository Setup
- Step 2: IAM Roles
- Step 3: EC2 Configuration
- Step 4: CodeDeploy Setup
- Step 5: CodePipeline Integration
- Conclusion
Technologies Used:
- GitHub: Stores the application’s source code.
- AWS CodePipeline: Detects changes in the repository, triggers builds, and initiates deployments.
- AWS CodeBuild: Builds your code into production-ready artifacts.
- AWS CodeDeploy: Automates the deployment of your builds onto EC2 instances.
- Amazon EC2: Hosts your web application.
- Amazon S3 (Optional): Stores build artifacts
- IAM: Manages secure permissions for the pipeline and services to interact.
Prerequisites
- AWS Account with administrative access
- GitHub account
- Basic understanding of AWS services
- Familiarity with React/Vite applications
Business Value
Key Benefits
- Improved Reliability: No more manual SSH deployments. CodeDeploy ensures consistency in every deployment.
- Faster Iteration: Push code and let the pipeline test and deploy automatically, speeding up feedback loops.
- Rollback Capability: If something goes wrong, CodeDeploy can roll back to a previous stable version quickly, minimizing downtime.
Problem Statement
Your team currently deploys updates by SSHing into a live EC2 instance—leading to human error, missed steps, and risky rollbacks. This tutorial fixes that by detecting GitHub changes automatically, deploying them via CodeDeploy, and using a repeatable, testable process.
Problem Solved
Traditional SSH-based deployments lead to:
- Human errors during manual deployments
- Inconsistent deployment steps
- Difficult rollbacks
- Security vulnerabilities
This solution implements industry best practices for automated, secure, and reliable deployments.
Ready to eliminate manual deployments? Let's build your pipeline.
Implementation Guide
Step 1: GitHub Repository
You can use your own repo or follow along with mine:
Fork this repository:
Github Repo: Github EC2
Repo Contains:
Repository Structure:
├── my-react-app/ # Sample React application
├── buildspec.yml # CodeBuild instructions
├── appspec.yml # CodeDeploy configuration
└── scripts/ # Deployment scripts
Step 2: IAM Roles
Important: If you attach a new role to an existing EC2 instance, reboot the instance so it recognizes the updated permissions.
EC2 Role
In the AWS Console search Roles -> Create role.
Trusted Entity: EC2 > EC2 use case.
Click Next
Add Permissions: Attach the AmazonEC2RoleforAWSCodeDeploy policy.
Click Next
Provide a name for the role.
- EC2CodeDeployRole
Review your settings then click "Create role".
CodeDeploy Role
Click Create role.
Trusted Entity: EC2 > EC2 use case.
Click Next
Add Permissions: Attach AWSCodeDeployRole.
Click Next
Provide a name for the role.
- CodeDeployRole
Review your settings then click "Create role".
Edit the trusted policy using:
Search for the newly created CodeDeployRole and select.
Choose the Trust relationships tab.
Choose Edit trust policy.
Copy and paste this trust policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": [
"codedeploy.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
Click "Update policy".
Step 3: EC2 Configuration
In the AWS console search up EC2 > Launch Instance.
Launch an Instance
Keep default settings.
Name and tags: Name your instance.
Application and OS Images: Ubuntu
Instance type: t2.micro
Key pair (login): Create or use an existing key pair.
Network settings: Use or create a security group allowing SSH (port 22) from your IP and HTTP (port 80) from the internet..
Under Advanced details
IAM instance profile: EC2CodeDeployRole
User data: Install the CodeDeploy agent on launch. Adjust region endpoints if you’re not using us-east-1:
Use this link to get your region to fetch your appropriate code-deploy region identifier
Edit this line in the script "aws-codedeploy-us-east-1.s3.us-east-1." with your appropriate region and identifier.
Copy and paste the code below.
#!/bin/bash
# Update system
apt update -y
# Install CodeDeploy Agent
apt install ruby-full -y
cd /home/ubuntu
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
./install auto
systemctl enable codedeploy-agent
systemctl start codedeploy-agent
Click Launch Instance and wait until it’s initialized..
Step 4: CodeDeploy Setup
We are setting up CodeDeploy first because it makes it easier to use and reference for later in the CodePipeline Section.
In the AWS search and select CodeDeploy > Create Application.
- Application name: vite-react-deploy
- Compute platform EC2/on-premise
Click Create application.
Click Create deployment group
Create deployment group





















Top comments (0)