AWS CodePipeline (CI/CD Pipeline)
Creating a CICD pipeline with AWS CodePipeline
Demonstration 2 Create 2 Stage Pipeline
In this guide, you’ll set up a simple two-stage CI/CD pipeline on AWS using CodeCommit for source control and CodeDeploy for deployment. We’ll deploy a sample web application to an EC2 instance following the AWS CodePipeline simple tutorial.
1. Create a CodeCommit Repository
- Sign in to the AWS Management Console and open CodeCommit.
- Ensure your region is set (we’re using us-west-2).
Note
Always match the region across CodeCommit, CodeDeploy, and EC2 to avoid cross-region issues.
- Click Create repository, name it MyDemoRepo, and confirm.
Once the repo is ready, note the clone instructions:
2. Clone the Repository Locally
On your laptop or workstation:
# Create a working directory
mkdir -p ~/demo/MyDemoRepo
cd ~/demo/MyDemoRepo
# Clone via HTTPS
git clone https://git-codecommit.us-west-2.amazonaws.com/v1/repos/MyDemoRepo .
ls
# (directory is currently empty)
3. Add the Sample Application
Download the sample app ZIP from the AWS tutorial and extract its contents.
You should see:
MyDemoRepo/ ├── appspec.yml ├── index.html ├── LICENSE.txt └── scripts/ ├── install_dependencies ├── start_server └── stop_server
Add, commit, and push:
git add . git commit -m "Add initial sample application files" git push origin master
Verify the files in the AWS Console:
4. Create an IAM Role for EC2 (CodeDeploy Agent)
In the IAM console, go to Roles > Create role:
Trusted entity: AWS service → EC2
Attach policies:
Policy Name Purpose AmazonEC2RoleforAWSCodeDeploy Grants CodeDeploy agent permissions AmazonSSMManagedInstanceCore Allows AWS Systems Manager operations
- Name the role EC2InstanceRole.
- Use this trust policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}
After creation, you’ll see:
5. Launch an EC2 Instance
- In the EC2 console (same region), choose Launch Instance.
- Configure as follows:
- Name tag: MyCodePipelineDemo
- AMI: Amazon Linux 2 (Free Tier)
- Instance type: t2.micro (Free Tier)
- Key pair: Proceed without one (demo only)
- Network: Enable auto-assign Public IP
- Security group:
- SSH (port 22) from My IP
- HTTP (port 80) from My IP
Under Advanced details, assign the EC2InstanceRole profile and click Launch instances.
6. Create a CodeDeploy Application & Deployment Group
6.1 Service Role for CodeDeploy
In IAM, choose Roles > Create role:
- Trusted entity: AWS service → CodeDeploy
- Managed policy: AWSCodeDeployRole
- Role name: CodeDeployRole
Use this trust policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "codedeploy.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}
6.2 Application & Deployment Group
Open CodeDeploy > Applications > Create application:
- Name: MyDemoApplication
- Compute platform: EC2/On-premises
Under Deployment groups, click Create deployment group:
- Name: MyDemoDeploymentGroup
- Service role: CodeDeployRole
- Deployment type: In-place
- Environment configuration: Tag instances
Name = MyCodePipelineDemo
- Load balancing: Disabled
- Agent configuration: AWS Systems Manager
When complete, review details:
7. Create the CodePipeline
In CodePipeline, click Create pipeline and configure:
- Pipeline name: MyFirstPipeline
- Service role: New service role
Source Stage
- Provider: AWS CodeCommit
- Repository name: MyDemoRepo
- Branch name: master
Skip Build
Choose Skip build stage.
Deploy Stage
- Action provider: AWS CodeDeploy
- Region: US West (Oregon)
- Application name: MyDemoApplication
- Deployment group: MyDemoDeploymentGroup
Review and click Create pipeline. The pipeline will start automatically:
8. Verify the Initial Deployment
Once Source and Deploy stages complete, get the Public IPv4 DNS of your EC2 instance:
Paste the address into your browser to see the welcome page:
9. Update the Application and Redeploy
Modify
index.html
locally. Example update:<!DOCTYPE html> <html> <head> <title>Updated Sample Deployment</title> <style> body { background-color: #CCFFCC; font-family: Arial, sans-serif; } h1 { font-size: 250%; margin-bottom: 0; } h2 { font-size: 175%; margin-bottom: 0; } </style> </head> <body> <div align="center"><h1>Updated Sample Deployment</h1></div> <div align="center"><h2>Deployed via CodePipeline, CodeCommit & CodeDeploy.</h2></div> <div align="center"> <p>Learn more:</p> <p><a href="https://docs.aws.amazon.com/codepipeline/latest/userguide/">CodePipeline User Guide</a></p> <p><a href="https://docs.aws.amazon.com/codecommit/latest/userguide/">CodeCommit User Guide</a></p> <p><a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/">CodeDeploy User Guide</a></p> </div> </body> </html>
Commit and push:
git add index.html git commit -m "Update index.html for new deployment" git push origin master
The pipeline auto-triggers and redeploys:
After deployment, refresh to view changes:
Conclusion
You’ve successfully created and tested a two-stage AWS CodePipeline using CodeCommit and CodeDeploy. In this lesson you:
- Set up and cloned a CodeCommit repository
- Added a sample web application
- Configured IAM roles for EC2 and CodeDeploy
- Launched an EC2 instance with the CodeDeploy agent
- Defined a CodeDeploy application and deployment group
- Built a Source → Deploy pipeline
- Verified initial deployment and automated updates
Up next: we’ll extend this pipeline with build and test stages for a complete four-stage CI/CD workflow.
References
Watch Video
Watch video content
Practice Lab
Practice lab