Automating Container Delivery on AWS: Building a CI/CD Pipeline for a Dockerized Web App on ECS Fargate
DEV Community

Automating Container Delivery on AWS: Building a CI/CD Pipeline for a Dockerized Web App on ECS Fargate

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.yml and 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

  • 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

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:

  • 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

  • CodeBuild service role (codeBuildServiceRole) - Trusted Principal: CodeBuild. Used For: Authenticate to ECR and push images; write logs; read/write the S3 artifact bucket
  • CodePipeline service role - Trusted Principal: CodePipeline. Used For: Pull source, start builds, read/write artifacts, register task definitions, update the ECS service
  • ECS task execution role (ecsTaskExecutionRole) - Trusted Principal: ECS tasks. Used For: 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.

  • 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 Dockerfile and buildspec.yml.

AWS CodeBuild: Runs buildspec.yml in 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)

  • 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
docker push <ACCOUNT_ID>.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",
      "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-build linked to himbukharidev/2048-game-ci-cd, S3 artifact bucket 2048-ci-cd-pipeline-artifacts1-605365943139-us-east-1-an, and codeBuildServiceRole (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

Representat

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.