
Build Your First CI/CD Pipeline on AWS Using S3, CodeBuild, and CodePipeline
Continuous Integration and Continuous Delivery (CI/CD) eliminates manual, error-prone software deployments by automating your entire build and release workflow. In this practical hands-on guide, you will learn how to build a fully automated CI/CD pipeline on AWS using GitHub, Amazon S3, AWS CodeBuild, and AWS CodePipeline—enabling automatic build and site deployment every time you push new code.
1. Introduction
In modern software development, delivering code manually every time can be time-consuming and error-prone. This is where CI/CD (Continuous Integration and Continuous Delivery) becomes important.
AWS provides several services that make it possible to automate the software delivery process without managing your own build servers.
In this article, we will build a basic CI/CD pipeline using three AWS services:
- Amazon S3: Stores and hosts our static website.
- AWS CodeBuild: Builds and prepares our application.
- AWS CodePipeline: Automates the complete deployment workflow.
Our goal is simple: whenever we push a code change to our GitHub repository, AWS automatically builds the project and deploys the updated website to Amazon S3.
2. Understanding the Architecture

How it works: A developer pushes code to GitHub. CodePipeline detects the change, triggers CodeBuild, and then deploys the resulting build artifact to S3.
3. Prerequisites
Before starting, make sure you have:
- An active AWS account.
- Access to the AWS Management Console.
- A GitHub account.
- A basic understanding of HTML and GitHub.
- An AWS Region selected for your project (for example, Asia Pacific – Sydney or Mumbai).
We will use a simple static website as our sample application.
4. Step 1 – Create a GitHub Repository
First, create a new repository on GitHub.
Repository name:
aws-cicd-demo Add two files:
File 1:
index.html <!DOCTYPE html>
<html>
<head>
<title>My AWS CI/CD Project</title>
</head>
<body>
<h1>Hello from AWS!</h1>
<p>My first automated CI/CD deployment.</p>
</body>
</html>
File 2:
buildspec.yml This file contains instructions that AWS CodeBuild follows during the build process.
version: 0.2
phases:
build:
commands:
- echo "Starting build process..."
- echo "Preparing website files..."
- ls -la
artifacts:
files:
- index.htmlCommit and push both files to the
main branch.5. Step 2 – Create an Amazon S3 Bucket
Now we need a destination where our website files will be deployed.
- Open the AWS Management Console.
- Search for Amazon S3.
- Select Create bucket.
- Enter a globally unique bucket name, such as
my-aws-cicd-demo-site.
- Select your AWS Region.
- Keep the default security settings initially.
- Click Create bucket.
The bucket will act as the storage destination for our deployed website.
Optional: Enable static website hosting
If you want to access the website directly through an S3 website endpoint:
- Open your bucket.
- Navigate to Properties.
- Find Static website hosting.
- Select Edit and enable it.
- Set the index document to
index.html.
- Save changes.
For a public S3 website endpoint, additional public-access configuration and a bucket policy are required. Public bucket access is not recommended for production. For production websites, prefer CloudFront with Origin Access Control (OAC).
6. Step 3 – Create an AWS CodeBuild Project
AWS CodeBuild is a fully managed build service that compiles source code, runs tests, and prepares deployment files.
Follow these steps:
- Search for AWS CodeBuild.
- Select Build projects.
- Click Create build project.
- Enter the following details:
Setting | Value |
|---|---|
Project name | aws-cicd-build |
Source provider | GitHub |
Repository | aws-cicd-demo |
Branch | main |
Environment | Managed image |
Operating system | Amazon Linux |
Runtime | Standard |
Buildspec | Use a buildspec file |
Connect your GitHub account using the AWS managed GitHub App (CodeConnections) when prompted.
Configure the build environment
Choose a suitable managed image and environment type.
Under Buildspec, select:
Use a buildspec file
Make sure
buildspec.yml exists in the root of your GitHub repository.Configure IAM permissions
CodeBuild requires an IAM service role to execute the build.
Allow the role to:
- Read the source artifact.
- Write the build artifact to the configured artifact destination.
- Write build logs to CloudWatch Logs.
Use least-privilege permissions instead of unrestricted administrator access.
Click Create build project.
7. Step 4 – Create AWS CodePipeline
Now comes the most important part: connecting everything together.
- Search for AWS CodePipeline.
- Select Pipelines.
- Click Create pipeline.
- Enter the pipeline name:
aws-cicd-pipeline - Choose New service role or an existing appropriately configured service role.
- Select the pipeline execution mode. For this beginner project, Superseded is a reasonable default.
Configure the Source stage
Select the following:
Setting | Value |
|---|---|
Source provider | GitHub (via GitHub App) |
Connection | Your GitHub connection |
Repository | aws-cicd-demo |
Branch | main |
Output artifact | SourceArtifact |
This stage monitors your GitHub repository for code changes.
Configure the Build stage
Choose:
- Build provider: AWS CodeBuild
- Region: Same region as your CodeBuild project
- Project name:
aws-cicd-build
- Input artifact:
SourceArtifact
- Output artifact:
BuildArtifact
This tells CodePipeline to send the source files to CodeBuild and collect the resulting build artifact.
Configure the Deploy stage
Choose:
- Deploy provider: Amazon S3
- Region: Same region as your S3 bucket
- Bucket: Your previously created S3 bucket
- S3 object key: Leave blank for deployment to the bucket root.
- Input artifact:
BuildArtifact
Click Create pipeline.
Important: Your CodePipeline service role must have permission to use the GitHub connection, start CodeBuild, access the relevant artifacts, and deploy files to the specified S3 bucket. Configure permissions for each service using least privilege.
8. Step 5 – Test the CI/CD Pipeline
Once the pipeline is created, AWS will automatically execute the stages.
You should see three stages:
1. Source
2. Build
3. Deploy
To test the pipeline:
- Open your GitHub repository.
- Edit the text inside
index.html.
- Change the heading to
My CI/CD Pipeline is Working!.
- Commit the changes to the
mainbranch.
- Open AWS CodePipeline.
- Select your pipeline and monitor its execution.
If everything is configured correctly, all three stages should complete successfully.
Now open your S3 bucket and check whether the updated
index.html file has been deployed.If static website hosting is configured, open its website endpoint to view the updated website.
9. Understanding the Role of Each AWS Service
AWS service | Main responsibility |
|---|---|
Amazon S3 | Stores website files and serves static content |
AWS CodeBuild | Executes build instructions and generates artifacts |
AWS CodePipeline | Coordinates and automates the deployment workflow |
AWS IAM | Controls permissions between AWS services |
Amazon CloudWatch | Stores build logs and helps troubleshoot errors |
One important detail: CodePipeline also uses an S3 artifact bucket to temporarily store source and build artifacts during pipeline execution. This is separate from your final website bucket.
10. Common Errors and Troubleshooting
Beginners may encounter some common issues during implementation.
Error | Possible solution |
|---|---|
GitHub connection failed | Check CodeConnections authorization and permissions |
Build failed | Verify the buildspec.yml file and build logs |
Access denied | Check IAM service-role permissions |
S3 deployment failed | Verify the bucket name and deployment permissions |
Website not loading | Check static hosting configuration and access permissions |
Updated files not visible | Verify the deployment stage and browser cache |
Useful troubleshooting tip: If a pipeline stage fails, open the failed action and inspect its execution details. For CodeBuild errors, check the associated CloudWatch Logs.
11. Cost and Security Considerations
Before experimenting with AWS services, remember that some resources can incur charges.
- CodeBuild charges depend on build duration and compute type.
- S3 may incur storage and request charges.
- CodePipeline pricing depends on the pipeline type and applicable pricing model.
- CloudWatch Logs may incur storage charges.
To manage costs:
- Check the AWS Free Tier eligibility and current service pricing.
- Create an AWS Budget with spending alerts.
- Delete unused resources after completing the experiment.
- Remove unnecessary S3 objects and artifact files.
- Review CloudWatch Logs and other resources during cleanup.
For security, avoid storing AWS access keys in GitHub repositories. Use IAM roles, least-privilege policies, and secure GitHub connections.
12. Conclusion
Building a CI/CD pipeline using Amazon S3, AWS CodeBuild, and AWS CodePipeline is an excellent beginner project for understanding cloud automation.
Through this implementation, we learned how to connect a GitHub repository with AWS, automate the build process, generate deployment artifacts, and publish updated website files to Amazon S3.
The biggest advantage is that developers no longer need to manually upload website files after every change. AWS handles the deployment workflow automatically.
This basic project can also be extended with additional services such as:
- AWS Lambda: Introduce serverless application functionality.
- Amazon CloudWatch: Monitor pipeline execution and application activity.
- Amazon CloudFront: Distribute website content globally.
- AWS CloudFormation: Automate infrastructure provisioning.
- Amazon SNS: Send notifications about pipeline success or failure.
Start small, build practically, and gradually move towards production-ready DevOps workflows!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article