Author: Muhammad Bilal Sharif Bukhari
LinkedIn: linkedin.com/in/bilalbukhari-dev
Repository: github.com/himbukharidev/2048-game-ci-cd
Evidence Policy: This article separates three things: (a) what I implemented and observed (console timestamps, screenshots, and build history), (b) what I learned or reasoned about, and (c) what I would add in a production engagement. Code samples are representative unless stated otherwise—they show the correct shape of a configuration rather than an exact transcript. Account IDs in code samples are replaced with
<ACCOUNT_ID>. I report no performance, cost, traffic, or availability figures because I did not measure any.
Abstract
A client, Alice, needed a browser-based 2048 game reachable from the public internet. I treated the request as a delivery-engineering problem, not a hosting problem. The deliverable was a repeatable path from git push to a running container, not a one-off deployment.
The resulting system runs a Docker image from Amazon ECR on AWS Fargate under an ECS service. AWS CodePipeline orchestrates Source, Build, and Deploy stages, while AWS CodeBuild builds and publishes the image.
The build history shows that the pipeline did not work on the first attempt. I diagnosed failures in account and region addressing, ECR authorization, build-phase failure propagation, Git workflow, and network exposure. Each is analyzed below by root cause rather than symptom. Finally, the evaluation section is explicit about the gap between this working system and a production-ready one: the deployment serves HTTP only, uses a mutable latest tag, has no load balancer, and exposes a task public IP that is not a stable address.
1. Project Background
1.1 The Requirement
Alice needed a web-based 2048 game deployed to the cloud and reachable from a browser. Because the application is a static front end (index.html, js/, style/, meta/), it needs only a web server—not a database or application tier. (Note: The business framing here is a scenario; I make no claims about Alice’s traffic, budget, or business outcomes.)
1.2 Why Manual Deployment Was the Wrong Shape
A manual deployment (build locally, push by hand, click through the console) works once. For a client, it introduces four structural weaknesses:
- Non-repeatability: A procedure living in my head or shell history cannot be audited or handed over.
- Environment drift: "Works on my laptop" depends on local tool versions. Building in a managed, versioned environment removes that variable.
- Human error at the seams: My own mistakes during this project (a wrong account ID, a wrong region, a malformed Git command) were all manual-step errors. Encoding steps in
buildspec.ymland a pipeline definition converts repeated risks into one-time fixes. - Delivery latency: If every change requires a human to rebuild, push, and redeploy, small fixes get deferred.
1.3 Objectives
| # | Objective | Status |
|---|---|---|
| O1 | Containerize the application | ✅ Implemented |
| O2 | Store images in a private registry | ✅ Implemented (ECR) |
| O3 | Run containers without managing servers | ✅ Implemented (ECS on Fargate) |
| O4 | Public HTTP reachability | ✅ Implemented (task public IP, port 80) |
| O5 | Automated build and deploy on commit | ✅ Implemented (CodePipeline, CodeBuild, ECS deploy action) |
| O6 | HTTPS, stable DNS, high availability | ❌ Not implemented (see Section 8) |
2. Technical Architecture
2.1 System Diagram

Diagram 1. System architecture: commit to running container.
2.2 Containerization Layer
A Dockerfile is a declarative recipe specifying the base image, files to include, and the process to start. Each instruction produces a filesystem layer.
Representative example (the actual file is in the repository):
FROM nginx:alpine COPY . /usr/share/nginx/html EXPOSE 80 Image vs. Container: An image is an immutable, layered, content-addressed artifact. A container is a running process isolated using kernel namespaces and cgroups, started from an image. Operationally, ECR stores images and ECS runs containers—the two are connected only by the image URI.
An ECR image URI has a precise structure:
<ACCOUNT_ID>[.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest](https://.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest) └────┬─────┘ └───┬───┘ └─────┬──────┘ └─┬──┘ account ID region repository tag Three of those segments encode where the image lives. Two of my failures (Sections 4.1 and 4.2) came from getting them wrong.
2.3 Registry and Orchestration
- Amazon ECR is a managed private registry. Pushing requires both an authorization token and explicit permissions on the repository.
- Amazon ECS is the control plane that decides what runs. Its vocabulary is hierarchical:
| Concept | Name in This Project | Role |
|---|---|---|
| Cluster | 2048-game-cluster | Logical grouping of capacity, tasks, and services |
| Task definition | 2048-game-task (revision 1) | Immutable blueprint: image, container name, ports, CPU/memory, roles, network mode, logging |
| Task | One instance of the blueprint | A running copy; ephemeral |
| Service | 2048-service | Controller that maintains the desired number of tasks and replaces failed ones |
| Container | 2048-container | The named container inside the task definition |
AWS Fargate is the compute engine behind the tasks. Selecting Fargate only when creating the cluster meant zero EC2 instances to patch, scale, or secure. Under Fargate’s awsvpc network mode, each task receives its own elastic network interface (ENI), security group, and private IP address in the VPC.
2.4 Identity: Three Roles, Three Principals
| Role | Trusted Principal | Used For |
|---|---|---|
CodeBuild service role (codeBuildServiceRole) | CodeBuild | Authenticate to ECR and push images; write logs; read/write the S3 artifact bucket |
| CodePipeline service role | CodePipeline | Pull source, start builds, read/write artifacts, register task definitions, update the ECS service |
ECS task execution role (ecsTaskExecutionRole) | ECS tasks | Used by the ECS agent to start the task: pull from ECR and write to CloudWatch Logs |
My task definition configures an execution role and no task role. The task role is the identity application code uses to call AWS APIs. Because a static game makes no AWS API calls, none is needed—applying least privilege so the container itself holds zero AWS permissions.
2.5 Network Layer

Diagram 2. Network layer: public subnet as used, private subnet as the studied alternative.
| Component | Function | Status in This Project |
|---|---|---|
| VPC | Isolated virtual network | Used |
| Subnet | IP range within one AZ; "public" or "private" is defined by its route table, not its name | Used (public-style, since tasks were reachable via public IP) |
| Internet Gateway (IGW) | Bidirectional path between a VPC and the internet | Necessarily in place (the task was reachable publicly) |
| NAT Gateway | Outbound-only internet access for private subnets | Studied as an alternative; not evidenced as deployed |
| S3 Gateway Endpoint | Route-table target keeping VPC-to-S3 traffic on the AWS network | Studied as an alternative; not evidenced as deployed |
| Security group | Stateful, per-ENI virtual firewall | AllowHttp: inbound TCP 80 |
| Public vs. private IP | Private IP is VPC-internal; public IP is mapped by AWS for internet reachability (ephemeral for ECS tasks) | Task had both |
Architecture Note: ECR image layers are served from Amazon S3. Consequently, a task in a private subnet without internet egress needs ECR interface endpoints and an S3 gateway endpoint (or a NAT gateway) to pull its image.
2.6 Delivery Layer
- GitHub: Source of truth holding
Dockerfileandbuildspec.yml. - AWS CodeBuild: Runs
buildspec.ymlin a managed, ephemeral build environment to build and push the image. It does not deploy. - AWS CodePipeline: Orchestrates stages and invokes the ECS deploy action. It does not build.
- Amazon S3: Stores and transfers artifacts between stages (e.g.,
2048-ci-cd-pipeline-artifacts1-<account>-us-east-1-an). -
imagedefinitions.json: The handoff contract between Build and Deploy (Section 3, Step 16). - Amazon CloudWatch Logs: Captures container and build output—the first place to inspect when anything fails.
2.7 Dependency Chain
The services form a strict dependency chain where each link fails differently:
- Source link: CodePipeline can only build what GitHub delivers.
- Identity & addressing: CodeBuild can only push where its role is authorized and the URI is accurate.
- Naming contract: ECS can only deploy what ECR holds, matched by container name in
imagedefinitions.json. - Platform permissions: A task can only start if the execution role can pull the image and the network reaches the registry.
- Exposure: A user can only reach the app if the public IP, route table, and security group align.
3. End-to-End Deployment Lifecycle
Observed Chronology (UTC+5, 22–23 Nov 2026)
| Time | Event |
|---|---|
| 22 Nov, 19:37 | Image pushed manually from my machine to ECR (latest, ~64 MB) |
| 22 Nov, 21:24 | Task definition 2048-game-task:1 created |
| 22 Nov, 21:36 | ECS service deployment started |
| 22 Nov, 21:37 | Task created; image pull completed in ~3 seconds |
| 22 Nov, ~22:42 | Initial commit visible in GitHub repository |
| 22 Nov, 23:43 | CodeBuild project 2048-game-build created |
| 22 Nov, ~23:45 | Builds #1 and #2 failed after 31 seconds each |
| 23 Nov, 00:15 | CodeBuild build #7 succeeded |
| 23 Nov, later | Pipeline executions on commits 52b1c54b and 34c4f65e passed Source, Build, and Deploy |
I deliberately executed the first deployment manually and automated afterward to isolate failure domains. Once a hand-pushed container runs cleanly under ECS, any subsequent failure is isolated to the CI/CD pipeline rather than the application or ECS configuration. (CLI commands below are reproducible equivalents of my console actions.)
Step 1: Prepare the Application
Used the static 2048 game repository containing index.html, js/, meta/, style/, Dockerfile, and buildspec.yml.

Figure 1. The repository: application files plus the two infrastructure-relevant files, Dockerfile and buildspec.yml.
Step 2 & 3: Create the Dockerfile & Build the Image
docker build -t 2048-game:latest . Produces a versioned, content-cached immutable image exposing port 80.
Step 4, 5 & 6: Create ECR Repo, Authenticate, Tag, and Push
# 4. Create repository aws ecr create-repository --repository-name 2048-game-repo --region us-east-1 # 5. Authenticate Docker using a temporary STS-backed token aws ecr get-login-password --region us-east-1 \ | docker login --username AWS --password-stdin \ <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com # 6. Tag and push docker tag 2048-game:latest <ACCOUNT_ID>[.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest](https://.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest) docker push <ACCOUNT_ID>[.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest](https://.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest) 
Figure 2. Manual push to the corrected account and region: every layer pushed, then a final digest.
ECR listed the latest tag as an Image Index of 64.25 MB, alongside two untagged entries consistent with multi-manifest Docker builds.

Figure 3. ECR image listing after the manual push.
Step 7 & 8: Create the ECS Cluster with Fargate
Created 2048-game-cluster selecting Fargate only so AWS provisions isolated serverless compute per task without EC2 host management.

Figure 4. Cluster creation with the serverless “Fargate only” capacity option.
Step 9: Create the Task Definition
Representative structure (CPU/memory values shown are illustrative placeholders):
{ "family": "2048-game-task", "requiresCompatibilities": ["FARGATE"], "networkMode": "awsvpc", "cpu": "256", "memory": "512", "executionRoleArn": "arn:aws:iam::<ACCOUNT_ID>:role/ecsTaskExecutionRole", "containerDefinitions": [{ "name": "2048-container", "image": "<ACCOUNT_ID>[.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest](https://.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest)", "essential": true, "portMappings": [{ "containerPort": 80, "protocol": "tcp" }], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/ecs/2048-game-task", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } } }] } 
Figure 5. Task definition revision 1: Fargate, awsvpc networking, ecsTaskExecutionRole, no task role.
Step 10: Create the ECS Service
aws ecs create-service \ --cluster 2048-game-cluster --service-name 2048-service \ --task-definition 2048-game-task --desired-count 1 --launch-type FARGATE \ --network-configuration "awsvpcConfiguration={subnets=[<SUBNET_ID>],securityGroups=[<SG_ID>],assignPublicIp=ENABLED}" Unlike a standalone task, an ECS service reconciles desired vs. actual state and automatically replaces failed tasks.

Figure 6. The cluster page at 21:36 showing the 2048-service deployment in progress.
Step 11 & 12: Configure Security Groups & Verify Connectivity
Created security group AllowHttp (sg-039a0810d4935875b) admitting inbound HTTP (TCP 80) and enabled public IP assignment on the task ENI.

Figure 7. The AllowHttp security group: one inbound rule, HTTP over TCP 80.
The task transitioned to Running with image pull completing in 3 seconds, and the game loaded in a browser at http://35.175.225.1/ (verified both locally and from a friend's external laptop). Because ECS task public IPs are ephemeral across replacements, this is a test endpoint rather than a permanent address.

Figure 8. A running task belonging to 2048-service, using 2048-game-task:1, with the container’s image URI pointing at 2048-game-repo:latest.
Step 13 & 14: Connect GitHub & Configure CodeBuild
- Connected GitHub to CodePipeline via GitHub (via OAuth app) to detect commits.
- Created CodeBuild project
2048-game-buildlinked tohimbukharidev/2048-game-ci-cd, S3 artifact bucket2048-ci-cd-pipeline-artifacts1-605365943139-us-east-1-an, andcodeBuildServiceRole(with privileged mode enabled so the Docker daemon can build images inside the build container).

Figure 9. The 2048-game-build project: GitHub source, S3 artifact location, and a dedicated service role.
Step 15 & 16: Write buildspec.yml and Generate imagedefinitions.json
Representative buildspec.yml dynamically deriving account ID and region from the CodeBuild environment:
version: 0.2 env: variables: REPO_NAME: 2048-game-repo CONTAINER_NAME: 2048-container phases: pre_build: commands: - ACCOUNT_ID=$(echo "$CODEBUILD_BUILD_ARN" | cut -d: -f5) - REGISTRY="$ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com" - aws ecr get-login-password --region "$AWS_DEFAULT_REGION" | docker login --username AWS --password-stdin "$REGISTRY" build: commands: - docker build -t "$REPO_NAME:latest" . - docker tag "$REPO_NAME:latest" "$REGISTRY/$REPO_NAME:latest" post_build: commands: - docker push "$REGISTRY/$REPO_NAME:latest" - printf '[{"name":"%s","imageUri":"%s"}]' "$CONTAINER_NAME" "$REGISTRY/$REPO_NAME:latest" > imagedefinitions.json artifacts: files: - imagedefinitions.json Output imagedefinitions.json contract consumed by ECS deploy:
[ { "name": "2048-container", "imageUri": "<ACCOUNT_ID>[.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest](https://.dkr.ecr.us-east-1.amazonaws.com/2048-game-repo:latest)" } ] Step 17, 18 & 19: Assemble CodePipeline & Automate ECS Deployment
Created 2048-game-pipeline chaining Source (GitHub) $\rightarrow$ Build (CodeBuild) $\rightarrow$ Deploy (Amazon ECS) using S3 for inter-stage artifacts, targeting 2048-game-cluster and 2048-service.

Figure 10. The pipeline after creation: Source, Build, and Deploy all succeeded for commit 52b1c54b.
4. Troubleshooting and Engineering Challenges
The CodeBuild history shows builds #1 and #2 failing after 31 seconds each before build #7 succeeded.

Figure 11. Early build history: builds #1 and #2 both failed after 31 seconds.
Part A: Conceptual Challenges
| Challenge | What I Had to Resolve | Resolution |
|---|---|---|
| Cluster vs. task definition vs. task vs. service | Sounded interchangeable initially | Cluster = boundary; task definition = blueprint; task = running instance; service = controller maintaining desired state |
| Fargate vs. EC2 | Why the console offers multiple capacity modes | Fargate removes host management; EC2 trades control for operational burden |
| Why ECS needs IAM roles | Why "my account" isn't enough | AWS services act as distinct principals needing delegated, scoped permissions |
| Why services need separate roles | Why one broad role isn't used | Narrow responsibilities keep grants minimal and failures attributable |
| Purpose of security groups | Why a running task timed out | Stateful per-ENI virtual firewalls default-deny all inbound traffic |
| VPC gateways | IGW vs. NAT vs. S3 endpoint | IGW enables public paths; NAT gives private subnets outbound internet; S3 endpoint keeps S3 traffic inside AWS |
| S3's role in the pipeline | Why storage appears in a deploy pipeline | Artifact handoff store between independent stages |
| Why CodePipeline needs its own role | Why CodeBuild's role didn't suffice | Orchestration permissions (RegisterTaskDefinition, UpdateService, PassRole) differ from build permissions |
Part B: Operational Failures (Root-Cause Analysis)
4.1 Wrong Account ID in the Registry URI
- Symptom:
docker pushfailed even thoughdocker loginsucceeded. - Cause: The registry URI in
buildspec.ymlpointed to a different AWS account ID than the CodeBuild role and ECR repository. - Resolution: Aligned the URI with the repository-owning account and switched to deriving
ACCOUNT_IDdynamically from$CODEBUILD_BUILD_ARN. - Lesson: Never hardcode composite registry coordinates that the build environment already exposes.
4.2 Wrong Region (ap-south-1 vs. us-east-1)
- Symptom: ECR reported that
2048-game-repodid not exist. - Cause:
buildspec.ymlinitially targetedap-south-1(Mumbai) while the repository lived inus-east-1(N. Virginia). - Resolution: Aligned login region, registry host, and repository region to
us-east-1. - Lesson: When a cloud resource "does not exist," verify your region and account coordinates first.
4.3 Authentication Succeeded; Authorization Failed
- Symptom:
docker loginreported success, butdocker pushwas denied. - Cause:
ecr:GetAuthorizationTokenproves identity (authentication) but grants zero repository write permissions (authorization). - Resolution: Attached repository-scoped ECR push permissions (
InitiateLayerUpload,UploadLayerPart,CompleteLayerUpload,PutImage,BatchCheckLayerAvailability) tocodeBuildServiceRole.
4.4 Cascading Failure: Root Cause vs. Downstream Symptom
- Symptom: Build failed in
UPLOAD_ARTIFACTSwith "no matching artifact paths found." - Cause: Not an artifact config bug. Because
docker pushexited non-zero inPOST_BUILD, CodeBuild halted the phase before running theprintfcommand that generatedimagedefinitions.json. - Resolution: Fixing the ECR push permission resolved the artifact error automatically on Build
#7. - Lesson: In cascading failures, the last error is the loudest, while the first failing command is the root cause.

Diagram 3. Failure propagation: a failed push in POST_BUILD cascades to the artifact error.

Figure 12. Build #7: Succeeded, with a resolved source version beginning 52b1c54, matching the commit shown in the pipeline.
4.5 Public Access & 4.6 Git Workflow
- Network Exposure: Treated "container healthy" and "service reachable" as separate claims, verifying public IP assignment, route table IGW path, and
AllowHttpTCP 80 rules independently. - Git Workflow: Corrected
git push -m 'message'(invalid flag onpush) togit add .$\rightarrow$git commit -m "message"$\rightarrow$git push, since CodePipeline reacts to remote commits rather than local disk edits.
5. Security and IAM Deep Dive
5.1 Temporary Credentials via Roles (No Static Keys)
Pipelines should never store long-lived IAM user access keys. CodeBuild, CodePipeline, and ECS tasks each assume dedicated IAM roles and receive short-lived credentials from AWS STS.
5.2 Trust Policy vs. Permission Policy
Every IAM role separates who can assume it (trust policy) from what it can do (permission policy):
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Service": "ecs-tasks.amazonaws.com" }, "Action": "sts:AssumeRole" }] } 5.3 Minimal ECR Push Policy for CodeBuild
ecr:GetAuthorizationToken is account-wide and requires "Resource": "*", whereas layer upload and manifest actions are pinned strictly to the target repository ARN:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EcrLogin", "Effect": "Allow", "Action": "ecr:GetAuthorizationToken", "Resource": "*" }, { "Sid": "EcrPushToOneRepo", "Effect": "Allow", "Action": [ "ecr:BatchCheckLayerAvailability", "ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload", "ecr:PutImage" ], "Resource": "arn:aws:ecr:us-east-1:<ACCOUNT_ID>:repository/2048-game-repo" } ] } 5.4 ECS Task Execution Role & iam:PassRole
-
ecsTaskExecutionRole: UsesAmazonECSTaskExecutionRolePolicyto pull images from ECR and write logs to CloudWatch Logs (opposite direction of CodeBuild's push). -
iam:PassRole: Prevents privilege escalation when CodePipeline registers a task definition referencingecsTaskExecutionRole:
{ "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::<ACCOUNT_ID>:role/ecsTaskExecutionRole", "Condition": { "StringEqualsIfExists": { "iam:PassedToService": "ecs-tasks.amazonaws.com" } } } 6. CI/CD Architecture and Automation
6.1 Responsibility Matrix
| Operation | Responsible Component |
|---|---|
| Detect new commit & trigger workflow | CodePipeline (Source stage) |
| Supply source code archive to build | CodePipeline via S3 artifact bucket |
| Authenticate to ECR; build, tag, and push image | CodeBuild |
Generate imagedefinitions.json | CodeBuild (buildspec.yml) |
| Register new task definition revision & update service | CodePipeline ECS standard deploy action |
| Pull image and launch replacement tasks | ECS using ecsTaskExecutionRole |
6.2 Execution Sequence

Diagram 4. Execution sequence of one pipeline run.
Because the pipeline has no manual approval gate, every commit passing Build proceeds directly to Deploy (continuous deployment behavior). Each stage displays the exact commit SHA (52b1c54b, 34c4f65e), turning "what is currently deployed?" into an auditable record.

Figure 13. A later pipeline execution on commit 34c4f65e: Source, Build, and Deploy all succeeded again with no manual step.

Figure 14. The live deployment running in the browser over HTTP ("2048 by Me"), confirming the updated container image was automatically built and served by ECS Fargate.
7. Architectural Decisions and Alternatives
| Decision | Chosen | Alternative | Why This Fit Scope | Where the Alternative Wins |
|---|---|---|---|---|
| Packaging | Docker | VM / host install | Reproducible, portable artifact | Legacy non-containerizable apps |
| Registry | Amazon ECR | Docker Hub | Native same-account IAM auth | Public distribution or multi-cloud |
| Orchestration | Amazon ECS | Amazon EKS | Minimal operational overhead for one service | Complex microservices, K8s ecosystem |
| Compute | AWS Fargate | ECS on EC2 | Zero host patching or capacity planning | Sustained high utilization, custom instance types |
| Build | CodeBuild | Local builds | Clean, logged, repeatable environment | Fast local inner-loop iteration |
| Release | CodePipeline | Manual deploy | Repeatable, commit-triggered, auditable | One-off throwaway prototypes |
| Networking | Public subnet + IGW | Private subnet + NAT/Endpoints | Fewest moving parts for a public static demo | Sensitive workloads behind a load balancer |
8. Professional Engineering Evaluation
8.1 What Works Well
- Full commit-to-container automation verified across multiple Git commits.
- Strict IAM separation of duties across three service roles, with zero AWS permissions granted to the application container.
- Serverless operations requiring zero OS patching.

