By Muhammad Bilal Sharif Bukhari · GitHub → CodePipeline → CodeBuild → ECR → ECS Fargate
The 3 a.m. problem every developer knows
My client Lucy had a simple Dockerized 2048 game and a painful release routine: build the image on a laptop, push it by hand, open the AWS console, update the service, refresh the page, and pray.
One typo in a tag, one forgotten step, and the site was down. Every update took longer than the change itself.
So I gave myself one rule for this project: git push is the only deployment step. Everything after it must happen on its own.
Here is how I built it, and every wall I hit on the way.
What I built
A fully automated CI/CD pipeline on AWS (region us-east-1):
- A push to GitHub triggers AWS CodePipeline.
- AWS CodeBuild pulls the code, builds the Docker image, and tags it.
- The image is pushed to Amazon ECR.
- Amazon ECS on Fargate starts a new task with the fresh image and removes the old one.
No servers to patch. No manual builds. No console clicking.
The toolkit
| Service | Its job |
|---|---|
| GitHub | Source of truth and the pipeline trigger |
| AWS CodePipeline | Orchestrates Source → Build → Deploy |
| AWS CodeBuild | Builds and tags the Docker image |
| Amazon ECR | Private registry that stores the images |
| Amazon ECS (Fargate) | Runs the container with no servers to manage |
| IAM roles and policies | Let each service securely talk to the others |
Step 1: ECR repository and ECS cluster
I started with the foundations: a private ECR repository (game-2048-repo) and an ECS cluster (game-2048-cluster) using the Fargate launch type. For the task definition I chose a larger task size than the minimum, because I wanted the game to stay smooth and I didn't want resource limits to be a variable while debugging.
Before going further, I checked everything from the CLI. This habit saved me hours later, because the console can look fine while the wiring underneath is wrong.
aws ecs list-clusters aws ecs list-services --cluster game-2048-cluster Step 2: Containerizing the game
The game is static files served by Nginx, so the Dockerfile stays tiny:
FROM nginx:alpine COPY . /usr/share/nginx/html EXPOSE 80 I pushed the project to GitHub with a first commit. That repository became the trigger for everything else.
Step 3: CodeBuild, the engine room
CodeBuild reads a buildspec.yml from the repo. Mine logs in to ECR, builds, tags, pushes, and writes a small file called imagedefinitions.json that tells ECS which image to run.
version: 0.2 phases: pre_build: commands: - aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_URI build: commands: - docker build -t game-2048-repo . - docker tag game-2048-repo:latest $ECR_URI/game-2048-repo:latest post_build: commands: - docker push $ECR_URI/game-2048-repo:latest - printf '[{"name":"2048-container","imageUri":"%s"}]' $ECR_URI/game-2048-repo:latest > imagedefinitions.json artifacts: files: imagedefinitions.json Step 4: CodePipeline, connecting the dots
The last step was wiring three stages together: Source (GitHub), Build (CodeBuild), Deploy (ECS). When all three turned green, I pushed a tiny change and watched the whole thing roll out without touching the console.
🚧 Everything that broke (so yours doesn't)
This is the part I wish I'd read before starting. Every item below cost me real time.
1. CodeBuild couldn't push to ECR: no basic auth credentials
My first build died within seconds of reaching the push step. I double-checked the repo name, the region, and the login command, and all of them were right. The real culprit was the CodeBuild service role, which had no ECR permissions at all.
Fix: attach AmazonEC2ContainerRegistryPowerUser (or a tighter custom policy) to the role.
Lesson: when AWS says "auth," check the IAM role before you check your code.
2. Cannot connect to the Docker daemon
The build started, then failed the moment it ran docker build. CodeBuild doesn't allow Docker-in-Docker by default.
Fix: enable Privileged mode in the CodeBuild environment settings. It's one checkbox, and it's easy to miss.
3. Docker Hub toomanyrequests
One run worked and the next failed with a rate-limit error while pulling the base image. Shared build infrastructure hits Docker Hub's anonymous limits fast.
Fix: pull the base image from the Amazon ECR Public Gallery, or authenticate to Docker Hub inside the build.
4. The Deploy stage failed with an invalid imagedefinitions.json
This one humbled me. Source and Build were green, but Deploy kept failing, and I spent far too long staring at the pipeline instead of at the file. The name inside imagedefinitions.json must match the container name in the ECS task definition exactly, character for character. Mine had a small mismatch.
Fix: copy the container name from the task definition instead of typing it from memory, and make sure the file is declared under artifacts in buildspec.yml.
5. The task started and stopped immediately
The service kept launching tasks that died in seconds. The console said very little until I opened the stopped task and read the stopped reason, then checked the CloudWatch logs.
Fix: correct the container port to match the Dockerfile (80) and make sure the task has an execution role.
6. Task "Running," but the website wouldn't load
The most frustrating one, because everything looked healthy. The task was running and the pipeline was green, yet the browser just spun.
Fix: the security group. I needed to allow inbound HTTP on port 80, and the task needed a public IP to be reachable.
7. The browser shows "Not secure"
I hit this once the site finally loaded. It isn't a bug. It's plain HTTP.
Fix for production: put an Application Load Balancer with an ACM certificate in front of the service.
8. The ECS service never reached a steady state
Tasks kept being created, failing, and being replaced. ECS simply couldn't pull the image.
Fix: make sure the task execution role has AmazonECSTaskExecutionRolePolicy, and that the subnet has a network path to ECR (public IP, NAT gateway, or VPC endpoints).
9. The pipeline was green, but I still saw the old game
I pushed a visible change and the page didn't change. The pipeline was fine. The browser was caching, and I was reusing the latest tag.
Fix: hard-refresh first. For anything beyond a lab, tag images with the commit SHA so every release is traceable and rollbacks are easy.
10. Leftover resources
A pipeline, a cluster, a service, and a registry full of images don't clean themselves up.
Fix: when the project is finished, delete the service, cluster, pipeline, CodeBuild project, and ECR images.
💡 What I learned
- IAM is where most failures live. Nearly every error was some version of "service A isn't allowed to do X to service B." Learning to read those errors was the biggest skill I gained.
- Exact names matter. One mismatched container name broke an entire deployment.
- Logs beat guessing. CodeBuild logs and CloudWatch told me what was wrong every single time. I just had to read them first.
- Fargate removes servers, not networking. Security groups, subnets, and public IPs still decide whether your app is reachable.
- Verify from the CLI. The console shows what you think you built. The CLI shows what actually exists.
-
latestis a lab tag, not a production strategy. Version your images. - Working for a real client changes how you build. I had to explain why each service existed, not just make it work.
What I'd add next
- A test stage (linting or unit tests) before deployment
- An Application Load Balancer + HTTPS
- Infrastructure as Code with Terraform or CloudFormation
- Blue/green deployments for zero-downtime releases
- CloudWatch alarms for task health
Final thoughts
I started with a game and finished with a real DevOps workflow: GitHub → CodePipeline → CodeBuild → ECR → ECS Fargate, fully automated and serverless.
The best part is the feeling. I changed a line of code, pushed it, made a cup of tea, and the live site had already updated.
Thank you to Lucy for trusting me with this project. 🙌
If you're learning AWS, build this one. Nothing teaches you how CI/CD really works like watching it fail, fixing it, and seeing it go green.
What was the first thing that broke in your first pipeline? Tell me in the comments. 👇







