*By Rashid • Tags: aws, devops, docker, cicd
*

I built a complete CI/CD pipeline on AWS: every git push to GitHub now builds a Docker image and deploys it to the cloud automatically, with no manual steps.
In this post I’ll walk through what I built, the errors I hit, and how I fixed them. The errors taught me more than the happy path did.
The problem CI/CD solves
Without automation, deploying means building an image by hand, pushing it, and updating the server. That is slow, easy to get wrong, and leads to the classic “it works on my machine” problem. CI/CD automates build, test, and deploy so every release is consistent.
Architecture
GitHub → CodePipeline → CodeBuild → ECR → ECS Fargate → Users
(code) (orchestrator) (build) (images) (runs container)
Service Role
GitHub Source code
AWS CodePipeline Connects Source, Build, and Deploy stages
AWS CodeBuild Runs buildspec.yml, builds the Docker image, pushes it
Amazon ECR Private registry for Docker images
Amazon ECS (Fargate) Runs the container without managing servers
IAM Lets each service talk to the others
(Screenshot: green pipeline with Source, Build, Deploy)
Step 1: Build the image and push it to ECR
I used the open-source 2048 game, served by nginx. I created an ECR repository, then built and pushed the image from AWS CloudShell, which already has Docker installed:
aws ecr create-repository --repository-name 2048-game-repo --region us-east-1

docker build -t 2048-game .


aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin .dkr.ecr.us-east-1.amazonaws.com
docker tag 2048-game:latest .dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest
docker push .dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest
Step 2: Run it on ECS Fargate
I created an ECS cluster, a task definition (container name 2048-container, port 80), and a service with one task and a public IP. I also opened port 80 in the security group. Opening the task’s public IP in a browser showed the game.
I did this manually first on purpose, so I understood exactly what the pipeline would later automate.
(Screenshot: game running on the public IP)
Step 3: Put the code on GitHub
The course repo’s buildspec.yml contained someone else’s account ID and region. If I had left it, CodeBuild would have tried to log in to the wrong account. I replaced them with mine:
sed -i 's///g; s/ap-south-1/us-east-1/g' buildspec.yml
The key part of the file is the last command, which creates imagedefinitions.json. ECS uses it to know which image to deploy. The container name inside it must match the task definition exactly.
Step 4: CodeBuild
I created a service role, an S3 bucket for artifacts, and a build project connected to my GitHub repo. Two settings mattered:
• Use a buildspec file instead of “Insert build commands”
• Privileged mode enabled, which is required to run docker build inside CodeBuild
Step 5: CodePipeline
I created a pipeline with three stages: Source (GitHub App connection), Build (my CodeBuild project), and Deploy (Amazon ECS, using imagedefinitions.json).
Problems I hit and how I fixed them
This is the most valuable part of the project.

  1. Wrong account ID in buildspec.yml. The template had another account’s ID and region. Fix: replace them with my own values.
  2. “Build command should not be empty.” I had left CodeBuild on “Insert build commands”. Fix: switch to “Use a buildspec file”.
  3. Push rejected with “fetch first”. My new GitHub repo wasn’t empty. Since it was a fresh practice repo, I used git push --force. On a shared repo I would pull and merge instead.
  4. iam:PassRole AccessDenied in the Build stage. The pipeline role was not allowed to pass my CodeBuild role to CodeBuild. Fix: add an inline policy to the pipeline role, scoped to that one role: { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam:::role/codeBuildServiceRole" }] } Whenever one service hands a role to another, the caller needs PassRole. This is a very common real-world error.
  5. My new commit didn’t trigger the pipeline. The first execution was still the old one. I pushed an empty commit (git commit --allow-empty) and the pipeline ran with the latest code.
  6. A security lesson. My secret access key appeared in a screenshot. I treated it as compromised, deleted it, and created a new one. Never share keys, and avoid screenshots of terminals during aws configure. The final test I changed the page heading to “2048 by Rashid”, committed, and pushed. Source, Build, and Deploy ran on their own, and after a few minutes the live site showed the new title. That single git push was the whole point of the project. (Screenshot: live site showing the new heading) What I would change for production This is a learning setup. In production I would add: • An Application Load Balancer with a domain and HTTPS (the task’s public IP changes on every deploy) • Commit-hash image tags instead of latest, so rollbacks are easy • Automated tests and an image security scan in the pipeline • Least-privilege IAM instead of broad FullAccess policies • Infrastructure as Code with Terraform instead of console clicks • CloudWatch alarms and dashboards • Separate dev, staging, and prod environments, and at least two tasks across two Availability Zones Cost and cleanup The project cost very little, but only because I cleaned up afterward. Delete the pipeline, ECS service and cluster, CodeBuild project, ECR repository, S3 buckets, log groups, IAM roles, the GitHub connection, and any access keys. A running Fargate task keeps billing until you stop it. What I learned • How Docker, ECR, ECS Fargate, CodeBuild, and CodePipeline fit together • Why you use an IAM user instead of root, and why keys must stay private • How to read real AWS errors and fix them • Why automation beats manual deployment Next, I plan to rebuild this same project with Terraform and then with GitHub Actions. If you’re learning DevOps too, I’d love to hear what you’re building. Thanks for reading! Code: github.com/Rashid1148/2048-game-ci-cd