Automated CI/CD Deployment Using GitHub and AWS CodeDeploy
Introduction : -
Automated CI/CD Deployment Using GitHub and AWS CodeDeploy

Introduction : -
This document explains how to implement automated application deployment using GitHub and AWS CodeDeploy. It covers the process of configuring AWS resources, integrating a GitHub repository, and creating a CI/CD pipeline that automatically deploys application updates to EC2 instances whenever changes are pushed to the repository.
In this project, an EC2 instance was initially launched to configure the website environment manually. After completing the required setup, an Amazon Machine Image (AMI) was created from that instance and used in a Launch Template.
Alternatively, the Launch Template can be configured directly using User Data scripts, which automate the server setup during instance launch.
Below is the User Data script used for the Launch Template.
#!/bin/bash
hostnamectl set-hostname webapp-server
apt-get update -y
apt-get install -y apache2 ruby-full wget
systemctl start apache2
systemctl enable apache2
cd /home/ubuntu
wget https://aws-codedeploy-us-east-2.s3.us-east-2.amazonaws.com/latest/install
chmod +x install
./install auto
This script performs the following tasks:
- Sets the hostname for the instance
- Updates the package list
- Installs Apache, Ruby, and wget
- Starts and enables the Apache service
- Downloads and installs the AWS CodeDeploy agent
Sep 1: Create an AMI
After configuring the initial EC2 instance with all the required packages and services, create an Amazon Machine Image (AMI).
This AMI will contain the preconfigured environment and will be used for launching new instances automatically.
Step 2: Create a Launch Template
Once the AMI is created, the next step is to create a Launch Template.
Steps:
- Go to EC2 → Launch Templates
- Click Create Launch Template
- Select the AMI created earlier
- Choose the instance type
- Attach an IAM Instance Profile with the required permissions
- Configure networking and security groups if required
After completing these steps, the Launch Template will be ready for use with Auto Scaling Groups.
Step 3: Create an Auto Scaling Group
Now create an Auto Scaling Group (ASG) using the launch template.
Steps:
- Navigate to EC2 → Auto Scaling Groups
- Click Create Auto Scaling Group
- Select the Launch Template created earlier
- Configure the VPC and Availability Zones
- Attach a Load Balancer (optional but recommended for production)
- Configure the Target Tracking Scaling Policy
- Set the minimum, desired, and maximum instance count
The Auto Scaling Group ensures that the required number of EC2 instances are always running and can automatically scale based on demand.
Step 4: Configure Application Files in GitHub
Next, prepare the application repository in GitHub.
The repository should contain:
- Application files (for example, index.html)
- A CodeDeploy configuration file (appspec.yml)
- Deployment scripts
Example appspec.yml
version: 0.0
os: linux
file_exists_behavior: OVERWRITE
files:
- source: /
destination: /var/www/web-app/
hooks:
BeforeInstall:
- location: scripts/before_install.sh
timeout: 60
runas: root
Purpose of the appspec.yml
The appspec.yml file tells AWS CodeDeploy:
- Where to copy application files
- Which scripts to run during deployment
- In which order deployment steps should execute
Step 5: Create a CodeDeploy Application
Now configure AWS CodeDeploy.
Steps:
- Navigate to AWS CodeDeploy
- Click Create Application
- Select EC2/On-Premises as the compute platform
- Provide an Application Name
Next, create a Deployment Group. Select the deployment type and autoscaling groups.
Deployment Group Configuration
During the deployment group creation:
- Create or attach a CodeDeploy Service Role
- Select Auto Scaling Groups as the deployment target
- Configure Deployment Settings
- Attach the Load Balancer
The deployment group defines which servers should receive the application updates.
Step 6: Create a CI/CD Pipeline Using AWS CodePipeline
To automate deployments from GitHub, create a CodePipeline.
Steps:
- Go to AWS CodePipeline
- Click Create Pipeline
- Select Build Custom Pipeline
Select the Build the custom pipeline option,

Source Stage (GitHub)
In the Source stage:
- Select GitHub (via OAuth App) as the source provider
- Connect your GitHub account
- Select the Repository
- Choose the Branch (for example, main)
Whenever code is pushed to this branch, the pipeline will automatically trigger.
Here i select the source provider as GitHub (via OAuth app) option and make the connection,

Build Stage (Optional)
In this project, the build stage is skipped because the application is a static website.
If your application requires compilation or packaging, you can use AWS CodeBuild here.
Deploy Stage
In the Deploy stage:
- Select AWS CodeDeploy
- Choose the Application
- Select the Deployment Group created earlier
Review the configuration and create the pipeline.
Step 7: Deployment Process
Once the pipeline is created:
- Any code changes pushed to the GitHub repository
- Automatically trigger the CodePipeline
- CodePipeline sends the artifact to AWS CodeDeploy
- CodeDeploy deploys the application to EC2 instances in the Auto Scaling Group
This completes the fully automated CI/CD workflow.
Deployment Result
After the pipeline runs successfully, the application is deployed to the EC2 instances behind the Load Balancer.
Whenever a small change is pushed to GitHub, the deployment process will automatically trigger and update the application on the servers.


Conclusion
By integrating GitHub, AWS CodePipeline, and AWS CodeDeploy, we created a fully automated CI/CD pipeline that deploys application updates to EC2 instances without manual intervention.
Key benefits of this setup include:
- Automated deployments
- Reduced manual errors
- Faster release cycles
- Scalable infrastructure using Auto Scaling Groups
This architecture is suitable for web applications that require continuous deployment with minimal downtime.
메타데이터
- post_id
- 0b0aaafc66ec
- slug
- automated-ci-cd-deployment-using-github-and-aws-codedeploy-0b0aaafc66ec
- url
- https://medium.com/@visalvengara/automated-ci-cd-deployment-using-github-and-aws-codedeploy-0b0aaafc66ec
- canonical_url
- https://medium.com/@visalvengara/automated-ci-cd-deployment-using-github-and-aws-codedeploy-0b0aaafc66ec
- author_url
- https://medium.com/@visalvengara
- status
- ok
- fetched_at
- 2026-07-21 13:34:43