Building, debugging and rolling back a Dockerized 2048 game on ECS Fargate, with nothing but Git.
The tutorial said: click Next, click Next, click Create. Green checkmark. Ten minutes, done.
My pipeline said this:
Access denied to connection arn:aws:codeconnections:... Same service, same region, same "simple" project. The difference between the two is the whole reason I'm writing this. Happy-path tutorials teach you the buttons. Real accounts teach you IAM scope, YAML quirks and browser behaviour, usually in that order, usually at 1 a.m.
So I built a fully automated CI/CD pipeline for a Dockerized 2048 game: GitHub → CodePipeline → CodeBuild → ECR → ECS Fargate. Then I pushed a change to production, and rolled it back, without opening the AWS Console once.
Along the way I hit six problems. A repository that existed but wouldn't show up. A build container that refused to run Docker. A YAML error that blamed containers that weren't in my file. And a website that timed out because my browser quietly changed my URL. I'll show you each one, with the fix.
What you'll get
The architecture, the IAM policies that actually worked, 6 failures with their fixes, and proof that
git pushships andgit revertundoes it.
The big picture
Everything runs in us-east-1 (N. Virginia). I developed on Windows with VS Code, Git and PowerShell. The only manual step is a push to main. Everything after that is the pipeline's job.
[Developer · VS Code] │ git push / git revert (main) ▼ [GitHub · Haris1973/2048-game-ci-cd] │ AWS CodeConnections (GitHub App webhook) ▼ [CodePipeline · 2048-game-pipeline] ├─► Stage 1 · Source (pull commit snapshot) ├─► Stage 2 · Build (CodeBuild · privileged Docker build) │ ├─► push image ──► [ECR · 2048-game-repo:latest] │ └─► imagedefinitions.json ──► [S3 artifact bucket] └─► Stage 3 · Deploy (rolling ECS service update) ▼ [ECS Fargate · 2048-game-cluster] └─► 2048-container (nginx:alpine · TCP 80) - App: static HTML/CSS/JS 2048 game on
nginx:alpine, port 80, container name2048-container. - Source: GitHub repo
Haris1973/2048-game-ci-cd(main) via AWS CodeConnections (GitHub App). - Registry: private Amazon ECR repo
2048-game-repo, tag:latest. - Build: CodeBuild
2048-game-buildonaws/codebuild/amazonlinux-x86_64-standard:6.0, Privileged mode, driven bybuildspec.yml. - Artifacts:
imagedefinitions.jsonzipped asbuild-output.zipinto a dedicated S3 bucket. - Orchestration: CodePipeline
2048-game-pipeline: Source → Build → Deploy. - Compute: ECS on Fargate, cluster
2048-game-cluster, 0.5 vCPU, 1 GB RAM,awsvpcnetworking, security group open on TCP 80.
Step 1: Prove it works on my laptop
Before touching AWS, I wanted one boring fact confirmed: Docker works here. If it doesn't run locally, no cloud service will fix that.

Fig. 1: Docker Desktop on Windows, engine up and running before any cloud work.
The image is tiny on purpose. A static game needs a web server, not a runtime:
FROM nginx:alpine COPY . /usr/share/nginx/html EXPOSE 80 Then I pushed it to ECR by hand. This is the step I'd recommend to anyone: if the manual push fails, the automated one will fail too, and PowerShell is a much friendlier place to debug than a build log.
Fig. 2: Manual tag, ECR login (Login Succeeded) and push of 2048-game-repo:latest. Account details hidden.
Takeaway
Do every step by hand once. A pipeline only automates what you already understand.
Step 2: Somewhere to run it, somewhere to stash artifacts
On the runtime side I created the ECS task definition 2048-game-task: one essential container (2048-container), 0.5 vCPU, 1 GiB, awsvpc networking, and an execution role so Fargate can pull from ECR.
Fig. 3: Task definition 2048-game-task:1 on Fargate. ARN hidden.
CodePipeline moves files between stages through S3, so I gave it its own artifact bucket.
Fig. 4: The artifact bucket, created and waiting for build-output.zip. Account ID hidden.
Step 3: IAM, where the real work lives
CodeBuild runs as one role, codeBuildServiceRole. I attached three AWS managed policies (AmazonEC2ContainerRegistryFullAccess, AWSCodeBuildDeveloperAccess, AmazonS3FullAccess) and added two narrow inline policies of my own.
The first lets the pipeline update one specific ECS service and nothing else:
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["ecs:UpdateService", "ecs:DescribeServices"], "Resource": "arn:aws:ecs:us-east-1:<ACCOUNT_ID>:service/2048-game-cluster/<service-name>" }] } The second lets CodeBuild use the GitHub connection. Remember this one. It comes back in roadblock #3:
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["codeconnections:UseConnection", "codestar-connections:UseConnection"], "Resource": "arn:aws:codeconnections:us-east-1:<ACCOUNT_ID>:connection/<connection-id>" }] } Fig. 5: codeBuildServiceRole in the console: the one identity the whole build runs as.
Step 4: The buildspec and the first real build
buildspec.yml is the contract between the repo and CodeBuild: log in to ECR, build, tag, push, then write imagedefinitions.json so ECS knows which image to roll out. One detail matters more than it looks: the name in that file must match the container name in the task definition.
version: 0.2 phases: pre_build: commands: - echo Logging in to Amazon ECR... - aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com build: commands: - echo Building the Docker image... - docker build -t 2048-game . - docker tag 2048-game:latest <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest - echo Build complete post_build: commands: - echo Pushing the image to ECR... - docker push <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest - echo Writing image definitions... - printf '[{"name":"2048-container","imageUri":"%s"}]' <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest > imagedefinitions.json artifacts: files: - imagedefinitions.json And here's the log of it working, with the ECR login succeeding and docker build kicking off:
Fig. 6: CodeBuild log: ECR login succeeds in PRE_BUILD, then docker build starts. Account ID hidden.
Step 5: Wiring the pipeline
Three stages: Source (GitHub via GitHub App), Build (CodeBuild) and Deploy (Amazon ECS, fed by imagedefinitions.json). I picked Queued execution so quick successive pushes line up instead of overwriting each other.
Fig. 7: Pipeline settings: 2048-game-pipeline, Queued mode, new service role.
First run: three green stages.
Fig. 8: First end-to-end run: Source, Build and Deploy all succeeded.
That looks too easy, doesn't it? It is. Here is everything that went wrong on the way there.
Lessons from the trenches: 6 things that broke
1. The lab template that remembered someone else's account
My starter buildspec.yml came from a lab. Before pushing, I read it line by line and found two leftovers: a stale region (ap-south-1) and a template account ID. Pushed as-is, the build would have tried to log in to a registry that wasn't mine, in a region I wasn't using.
The second trap was quieter. VS Code had detected a .git folder in a parent directory of my workspace. Initialise or push from the wrong level and you end up with a nested repository and the wrong files on GitHub. I ran git status and checked the remote before the first push.
Takeaway
Search the project for
region,.dkr.ecr.and any 12-digit number before the first push. Rungit rev-parse --show-toplevelto confirm which repo you're really in.
2. The repository that existed but didn't
In CodeBuild's source step, the repository dropdown said "No results". The repo was there. The connection was healthy. So what was missing?
The answer was on GitHub, not AWS. I had reused an AWS Connector GitHub App installation from an earlier project, and the app's repository access was still limited to that old repo. The fix: open github.com/settings/installations, configure the AWS Connector app, and add the new repository. The dropdown filled in on refresh.
Fig. 9: Leftovers from my earlier static-web-pipeline project in the same account, the reason the reused GitHub App connection kept its old repository scope.
3. Access denied on webhook creation
CodeBuild tried to create the webhook and stopped with Access denied to connection arn:aws:codeconnections:.... The role could build and push, but it had no right to use the connection. Attaching the inline CodeConnectionsPolicy from Step 3 (codeconnections:UseConnection, plus the older codestar-connections:UseConnection) fixed it on the next attempt.
4. Docker needs a flag to run inside CodeBuild
A managed CodeBuild container doesn't give you a Docker daemon by default, so docker build has nothing to talk to. The fix is a single checkbox hiding under Additional configuration: enable Privileged. After that, the log went from errors to Running command docker build -t 2048-game .
Takeaway
If your buildspec uses
docker build,docker loginordocker push, tick Privileged before the first run, not after the first failure.
5. YAML_FILE_ERROR: wrong number of container tags, expected 1
This one had me staring. On my first automated push, the Build stage turned red before building anything. The DOWNLOAD_SOURCE phase failed with YAML_FILE_ERROR: wrong number of container tags, expected 1.
Container tags? My buildspec has no containers. The message points in the wrong direction: the real problem was stray formatting and multi-document separators in buildspec.yml.
Fig. 10: Build stage red on the first automated push (commit 09929258). Start rollback is offered, but the real fix was in the YAML.
git status showed the one modified file. I rewrote buildspec.yml as a single clean YAML document, committed it as Fix buildspec YAML formatting, and pushed.
Fig. 11: git status: buildspec.yml modified, ready to commit. Local path hidden.
The push triggered the pipeline on its own. Build picked up the new commit while Deploy still showed the previous release:
Fig. 12: Pipeline re-triggered by the fix: Build in progress on 69fcc75c.
A few minutes later, all three stages were green on the same commit.
Fig. 13: All three stages succeeded on 69fcc75c.
Takeaway
An error message that names the wrong thing is still a YAML error. Check separators, tabs and indentation first, and lint the file before you push.
6. The browser that changed my URL
The service was running. I copied the task's public IP, typed http://<Public-IP>, and got a timeout. The task was healthy. The security group allowed TCP 80. So why nothing?
Because desktop Chrome silently upgraded the request to https://, which means port 443, and nothing was listening there. There was no load balancer and no certificate in this design. The fix is to be explicit:
http://<Public-IP>:80 Fig. 14: ECS cluster: 2048-game-task:3 is Running, the previous revision 2 is Stopped. Cluster ARN hidden.
Cheat sheet
| Symptom | Fix |
|---|---|
| Stale region / account ID in buildspec | Search for ap-south-1, 12-digit IDs and .dkr.ecr. before pushing |
| Repository dropdown says No results | Add the repo to the GitHub App at github.com/settings/installations |
| Access denied to connection ... | Inline policy with codeconnections:UseConnection on the build role |
| docker build fails inside CodeBuild | Enable Privileged under Additional configuration |
| YAML_FILE_ERROR: wrong number of container tags | Rewrite buildspec.yml as one clean YAML document |
| Public IP times out in Chrome | Use http://<Public-IP>:80 explicitly |
The real test: ship forward, then roll back with Git
Forward deploy
To prove the whole thing worked, I changed something visible. In index.html I edited the h1.title heading so the page would show my own title instead of plain 2048.
Fig. 15: VS Code: editing the h1.title in index.html. Path and author details hidden.
I committed it (Changed game name to 2048 by Haris) and ran git push to main. GitHub showed the commit right away:
Fig. 16: The commit on main in the GitHub repository.
From there, no console clicks. The webhook woke CodePipeline, CodeBuild built and pushed the image, and ECS rolled out a new Fargate task. When it came up, the new title was live:
Fig. 17: The custom title, live on Fargate over plain HTTP. Public IP hidden.
Rollback with git revert
Now the part that makes CI/CD worth the effort. No hunting for an old image in ECR, no editing task definitions. Just Git:
git revert 09929258 --no-edit git push A revert creates a new commit that undoes the old one, so history stays intact and the pipeline treats it like any other change. It rebuilt, redeployed, and production went back to the original release.
Fig. 18: After the revert: the original 2048 title is back in production.
Why this matters
Rollback is the same operation as deployment: a commit. Same pipeline, same audit trail, no special procedure to remember under pressure.
From portfolio lab to production: 3 upgrades
This setup is deliberately simple. If it were carrying real traffic, these are the three changes I'd make first.
1. Application Load Balancer + AWS Certificate Manager
Put an ALB in front of Fargate and attach an ACM certificate. You get real HTTPS on 443, a stable DNS name instead of a changing task IP (goodbye, roadblock #6), health checks and smoother rolling deploys.
2. Immutable Git SHA image tags instead of :latest
My ECR repository still allows mutable tags, as the console shows. Tag every image with the commit SHA ($CODEBUILD_RESOLVED_SOURCE_VERSION) and write that tag into imagedefinitions.json. Each ECS task definition revision then points at one exact, permanent image, so a rollback can be a one-click redeploy of an older revision.
Fig. 19: ECR private registry with Tag immutability set to Mutable. Turning it on, plus SHA tags, is the first hardening step.
3. ECR automated vulnerability scanning
Enable scan on push. Every image the pipeline publishes gets checked against known CVEs, and you can alert or fail the pipeline on findings above a severity threshold before anything reaches Fargate.
Final thoughts
What stuck with me is how small each failure was: one GitHub App scope, one IAM action, one checkbox, one YAML separator, one URL scheme. Each takes five minutes to fix once you know it, and hours to find when you don't. Write your failures down. They're the part other engineers will actually search for.
Your turn
What's the most confusing error you've hit on a "simple" pipeline: IAM, a webhook, or something that looked like a code bug but wasn't? Tell me in the comments. I'm collecting them.

















