Introduction
Shipping software by hand is one of the quickest ways to introduce mistakes. Someone builds an image on their laptop, pushes it to a registry, logs into a console and clicks through a deployment. It works until the day a step is skipped, a wrong tag is deployed or the one person who knows the process is on leave.
Continuous Integration and Continuous Delivery (CI/CD) solves this by turning the release process into code that runs the same way every time. In this project I built a complete CI/CD pipeline on AWS that takes a change from a git push to a running container on Amazon ECS Fargate, with no manual steps in between.
To keep the focus on the pipeline rather than the application, I used the classic 2048 game as the workload. It is a static web app that is easy to containerize, and it gives an instantly visible result whenever a deployment succeeds.
Credit: the application source and project outline come from the ZTC projects learning repository. The AWS setup, IAM configuration and pipeline were built and verified by me.
At a glance
- Time: about 2 to 3 hours
- Cost: about $1 or less
- Result: every push to
mainis built, stored in ECR and deployed to ECS automatically
What the pipeline does
Whenever I push code to GitHub, three things happen automatically:
- Source: CodePipeline detects the push and fetches the latest code from GitHub.
- Build: CodeBuild runs the instructions in
buildspec.yml. It builds a Docker image, tags it, pushes it to Amazon ECR and produces a small file calledimagedefinitions.json. - Deploy: CodePipeline hands that file to Amazon ECS, which replaces the running container with the new image.

Architecture diagram of the CI/CD pipeline
Tech stack and why each piece is there
| Service | Role in the project |
|---|---|
| GitHub | Stores the source code and triggers the pipeline on every push |
| Docker + Nginx | Packages the app so it runs identically everywhere |
| Amazon ECR | Private registry that stores the Docker images |
| AWS CodeBuild | Managed build server that builds and pushes the image |
| Amazon S3 | Holds the build artifacts passed between stages |
| AWS CodePipeline | Orchestrates Source, Build and Deploy |
| Amazon ECS (Fargate) | Runs the container without any servers to manage |
| IAM | Gives each service only the access it needs |
I chose Fargate because it removes server management completely. There are no EC2 instances to patch or scale, so the pipeline is the only moving part, which is exactly what I wanted to learn.
Step 1: Containerize the application
The Dockerfile is intentionally small. It uses the official Nginx image, copies the game files into Nginx's web root and starts Nginx in the foreground so the container keeps running.
FROM nginx:latest COPY . /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] I built it locally first. Testing the container on my own machine before touching AWS means any problem at this stage is a Docker problem, not a cloud problem, which makes it much easier to diagnose.
docker build -t 2048-game . 
Docker image building successfully
Step 2: Store the image in Amazon ECR
Next I created a private repository in Amazon ECR. This is where CodeBuild will later push every new version of the image, and where ECS will pull it from.
To push the image I tagged it with the repository URI, authenticated Docker with a temporary ECR login token and pushed:
docker tag 2048-game:latest <ECR_URI>:latest aws ecr get-login-password --region <your-region> \ | docker login --username AWS --password-stdin <ECR_URI> docker push <ECR_URI>:latest The image appeared in the repository straight away.

Image stored in the ECR repository
Step 3: Deploy manually to ECS Fargate first
Before automating anything, I deployed the container by hand. This is the most useful habit I took from the project: if it does not work manually, a pipeline will only automate the failure. Having a known-good manual deployment also gives you something to compare against when the pipeline misbehaves.
The manual deployment had four parts:
- Cluster: a logical group for my tasks, created with the AWS Fargate (serverless) option.
- Task definition: the blueprint for the container. It names the container (
2048-container), points to the ECR image and maps port 80 to port 80. - Service: keeps the desired number of tasks (one) running and replaces any that stop. I placed it in the default VPC and enabled a public IP.
- Security group: allows inbound HTTP on port 80, otherwise the browser cannot reach the container.

ECS cluster created successfully
Once the task was running, I opened its public IP in a browser and the game loaded. That confirmed the image, the task definition, the networking and the security group were all correct.

The 2048 game served from the container on ECS
Step 4: Create my own GitHub repository
CodePipeline needs a repository I control so it can listen for pushes, so I created a new repository and pushed the project to it, along with a buildspec.yml in the root.
git init git add . git commit -m "Initial commit" git remote add origin <your-repository-url> git branch -M main git push -u origin main 
GitHub repository with the Dockerfile, buildspec.yml and game source
Step 5: Write the buildspec (the heart of CI)
buildspec.yml tells CodeBuild exactly what to do. It has three phases:
- pre_build: logs in to ECR so the build can push images.
- build: builds the Docker image and tags it with the ECR repository URI.
- post_build: pushes the image and writes
imagedefinitions.json.
version: 0.2 phases: pre_build: commands: - "echo Logging in to Amazon ECR..." - "aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <ECR_URI>" build: commands: - "echo Building the Docker image..." - "docker build -t 2048-game ." - "docker tag 2048-game:latest <ECR_URI>:latest" post_build: commands: - "echo Pushing the Docker image to Amazon ECR..." - "docker push <ECR_URI>:latest" - "echo Creating imagedefinitions.json for ECS deployment..." - 'printf ''[{"name":"2048-container","imageUri":"%s"}]'' "<ECR_URI>:latest" > imagedefinitions.json' artifacts: files: - imagedefinitions.json The most important detail is imagedefinitions.json. It is the bridge between CodeBuild and ECS: it tells the ECS deploy action which container to update and which image to use. The name value must match the container name in the task definition exactly, otherwise the Deploy stage fails.

buildspec.yml configured with my region, repository and container name
Step 6: Set up permissions with IAM
AWS services cannot act on each other by default, so CodeBuild needs an IAM role. I created codeBuildServiceRole with CodeBuild as the trusted entity and attached managed policies for ECR, CodeBuild and S3.
Then I added a small inline policy that lets CodeBuild update only my ECS service, rather than every service in the account:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["ecs:UpdateService", "ecs:DescribeServices"], "Resource": "<ECS_SERVICE_ARN>" } ] } This inline policy is a small example of least privilege: grant the narrowest permission that gets the job done. For a production setup I would tighten the managed policies the same way (more on that below).
Step 7: Create the S3 bucket and CodeBuild project
CodeBuild produces output such as imagedefinitions.json, so I created an S3 bucket to hold build artifacts. Then I created the CodeBuild project:
- Source: my GitHub repository, connected through an OAuth app credential managed by CodeBuild
- Service role: the existing
codeBuildServiceRole - Build instructions: use the
buildspec.ymlfile from the repository - Artifacts: stored in the S3 bucket
Before building the pipeline I triggered a build manually. Testing each stage on its own meant that when the full pipeline ran, any failure would be easy to place. The build succeeded, the image was pushed to ECR and imagedefinitions.json appeared in S3.

imagedefinitions.json stored in the S3 artifact bucket
Step 8: Connect everything with CodePipeline
Finally I created the pipeline, 2048-game-pipeline, with three stages:
| Stage | Provider | What it does |
|---|---|---|
| Source | GitHub (OAuth app) | Starts the pipeline when main changes |
| Build | AWS CodeBuild | Runs buildspec.yml |
| Deploy | Amazon ECS | Updates 2048-service using imagedefinitions.json |
I skipped the optional Test stage for this project. CodePipeline created its own service role, and the first run started immediately.
CodePipeline created with Source, Build and Deploy stages
Each stage turned green in turn, ending with a successful deployment to ECS.
Deploy stage succeeded
Step 9: The real test, a code change
A pipeline only proves itself when a change flows through it untouched. I edited the heading in index.html to "2048 by Me", then ran just three commands:
git add . git commit -m "Changed game name to 2048 by Me" git push -u origin main That was the only manual action. The push triggered the pipeline, CodeBuild built and pushed a fresh image, and ECS started a new task. The ECS console shows the old tasks stopped and the new one running: a rolling deployment that replaces the container without me touching the console.

ECS showing the new task running and older tasks stopped
Reloading the public IP showed the updated title.

The updated game live on ECS Fargate
Common problems and how to fix them
If you build this yourself, these are the places it most often goes wrong:
- Build fails at the ECR login or push: the CodeBuild role is missing ECR permissions, or the region or repository URI in
buildspec.ymlis wrong. - Deploy stage fails: the container
nameinimagedefinitions.jsondoes not match the task definition's container name. - Site does not load on the public IP: the security group does not allow inbound port 80, or the service does not have a public IP enabled.
- CodeBuild cannot update the service: the inline policy's resource ARN does not match your ECS service.
- Pipeline does not trigger on push: the Source stage is pointing at a different repository or branch.
In almost every case the answer was in the CodeBuild logs or the failed stage's details, so read those first.
What I learned
- Automate last. Get the manual deployment working, then automate it.
-
imagedefinitions.jsonis the contract between the build and the deployment. Small mismatches here cause the most confusing failures. - IAM is where most pipeline problems hide. Understanding which service needs which permission is half the work.
- Test each stage in isolation before chaining them together.
- Fargate keeps the focus on delivery, since there are no servers to look after.
How I would harden this for production
This project is designed for learning. For a real workload I would:
- Replace broad managed policies such as
AmazonS3FullAccesswith least-privilege, resource-scoped policies. - Pin the base image to a specific version instead of
nginx:latest. - Tag images with the commit SHA as well as
latest, so any release can be traced and rolled back. - Add a Test stage with linting and ECR image scanning before deployment.
- Put an Application Load Balancer in front of the service for a stable DNS name, HTTPS and health checks.
- Define all of the infrastructure as code with Terraform or CloudFormation.
- Use a GitHub App connection (CodeConnections) instead of the OAuth app, which AWS no longer recommends.
- Enable automatic rollback and add CloudWatch alarms.
Cost and cleanup
The whole project cost about $1 or less. To avoid ongoing charges, delete the resources when you are done: the pipeline, the CodeBuild project, the IAM roles and policies, the S3 bucket, the ECR repository, and finally the ECS service and cluster.
Conclusion
A single git push now takes code from my laptop to a running, containerized service on AWS, with no manual steps in between. The project gave me practical experience with the services that make up a real cloud delivery workflow and, more importantly, with how they depend on each other through IAM, artifacts and configuration.
Next, I plan to rebuild the same pipeline with Terraform and add an Application Load Balancer with HTTPS.
If you have built something similar or have suggestions, I would love to hear about it in the comments.
Connect with me: LinkedIn




