AWS Builder Center
How I Built a CI/CD Pipeline with AWS and GitHub Actions

How I Built a CI/CD Pipeline with AWS and GitHub Actions

A hands-on look at building a CI/CD pipeline using GitHub Actions, Docker, Amazon ECR, and Amazon ECS to automate application builds, container image publishing, and deployments.

Introduction

One of the areas I’ve been learning and working on in DevOps is CI/CD automation.
Earlier, deploying an application could involve several manual steps — building the application, creating a Docker image, pushing it to a container registry, and then updating the deployment.
I wanted to understand how these steps could be connected into one automated workflow.
For this setup, I worked with:
  • GitHub Actions – CI/CD automation
  • Docker – Application containerization
  • Amazon ECR – Container image storage
  • Amazon ECS – Container deployment and management
The overall flow looks like this:
Developer → GitHub → GitHub Actions → Docker → Amazon ECR → Amazon ECS → Application



1. GitHub – Source Code

The process starts when developers push code to the GitHub repository.
For example:
git add .
git commit -m "Update application"
git push
Once the code is pushed, GitHub Actions can automatically trigger the CI/CD workflow.
This removes the need to manually start the deployment process every time there is a code change.



2. GitHub Actions – CI/CD Automation

GitHub Actions is responsible for automating the pipeline.
A workflow can be defined inside:
.github/workflows/deploy.yml
The workflow can perform several stages:
Checkout → Build → Test → Docker Build → Push → Deploy
A simplified workflow looks like:
Code Push
↓
GitHub Actions
↓
Checkout Code
↓
Build Application
↓
Run Tests
↓
Build Docker Image
↓
Push Image to ECR
↓
Deploy to ECS
One thing I learned here is that a CI/CD pipeline is not just about deployment.
The pipeline should also provide a place to validate the code before it reaches the environment.



3. Docker – Containerizing the Application

After the application is built and tested, the next step is creating a Docker image.
A Docker file defines how the application should be packaged.
For example:
FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python", "app.py"]
The exact Docker file depends on the application.
The important idea is that the application and its required dependencies are packaged into a consistent container image.
This makes the application easier to move between environments.



4. Amazon ECR – Storing the Docker Image

Once the Docker image is created, it needs to be stored somewhere that ECS can access.
This is where Amazon Elastic Container Registry (ECR) comes in.
The pipeline builds the image and pushes it to an ECR repository.
The flow becomes:
GitHub Actions → Docker Build → Amazon ECR
For example:
my-application:latest
or, preferably, a unique version/tag:
my-application:abc1234
Using unique image tags makes it easier to identify exactly which version is running.
It also makes troubleshooting and rollback easier.



5. Amazon ECS – Deploying the Container

After the image is available in ECR, the next step is deploying it to Amazon ECS.
ECS retrieves the container image from ECR and starts the application using the configured ECS task definition.
The deployment flow is:
ECR → ECS Task → ECS Service → Running Container
The ECS service helps maintain the desired number of running tasks.
For example:
ECS Service
↓
┌─────────┐
│ Task 1 │
└─────────┘
┌─────────┐
│ Task 2 │
└─────────┘
If a task becomes unhealthy, ECS can replace it according to the service configuration.



Complete CI/CD Flow

The complete pipeline can be represented as:
Developer
│
▼
GitHub
│
Code Push
│
▼
GitHub Actions
│
┌──────────┴──────────┐
▼ ▼
Build/Test Docker Build
│
▼
Amazon ECR
│
▼
Amazon ECS
│
▼
Application
This automated flow significantly reduces manual deployment steps.



What Happens During a Deployment?

When a developer pushes new code:

Step 1

GitHub receives the code change.

Step 2

GitHub Actions starts the workflow.

Step 3

The pipeline checks out the latest code.

Step 4

The application is built and tests are executed.

Step 5

A new Docker image is created.

Step 6

The Docker image is pushed to Amazon ECR.

Step 7

The ECS deployment is updated to use the new image.

Step 8

ECS starts the new task and replaces the old version according to the deployment configuration.

Step 9

The application is tested to make sure the deployment is successful.



Challenges I Learned From

The most valuable part of working with CI/CD wasn't only getting the pipeline to work.
It was understanding what happens when something doesn't work.
Some common areas I learned to troubleshoot include:

GitHub Actions

  • Workflow failures
  • Incorrect environment variables
  • Authentication issues
  • Build failures

Docker

  • Dockerfile errors
  • Dependency installation problems
  • Image build failures
  • Container startup issues

ECR

  • Authentication problems
  • Incorrect repository names
  • Image tag issues
  • Push failures

ECS

  • Task startup failures
  • Incorrect task definitions
  • Container health-check failures
  • Incorrect environment variables
  • Image pull problems
This taught me to troubleshoot the pipeline stage by stage rather than treating the entire deployment as one problem.



Security Considerations

CI/CD pipelines also need to be designed with security in mind.
Credentials should not be hard-coded inside workflow files.
Instead, sensitive values should be managed using appropriate secret-management mechanisms.
For AWS authentication, a better approach is to use GitHub Actions with AWS IAM using short-lived credentials through OIDC, rather than storing long-lived AWS access keys in GitHub.
IAM permissions should also follow the principle of least privilege.
The GitHub Actions identity should only have the permissions required to perform the necessary build and deployment operations.



Why CI/CD Is Useful

A properly designed CI/CD pipeline provides several benefits:
✅ Less manual work ✅ Faster deployments ✅ Consistent deployment process ✅ Easier testing ✅ Better traceability ✅ Easier rollback ✅ Reduced human error
Most importantly, it gives developers a repeatable way to move changes from source code to a running application.



Key Learning

My biggest takeaway from this experience is that each tool has a specific responsibility:
GitHub → Source code
GitHub Actions → Automation
Docker → Containerization
Amazon ECR → Container image storage
Amazon ECS → Container deployment
When these services are connected properly, they create a simple and powerful CI/CD workflow.



Final Thoughts

Building and understanding this CI/CD flow gave me valuable hands-on experience with AWS and DevOps automation.
I'm continuing to improve my skills in:
AWS | DevOps | Terraform | Docker | Kubernetes | GitHub Actions | Prometheus | Grafana
There is still a lot more to learn, especially around secure deployments, automated testing, blue/green deployments, rollback strategies, and infrastructure as code.
Looking forward to building more and sharing what I learn with the AWS community.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article