The goal of this project is to build a fully automated, serverless CI/CD (Continuous Integration and Continuous Deployment) pipeline on Amazon Web Services (AWS) for a containerized 2048 web game. Whenever a developer pushes updated code to the main branch on GitHub, AWS automatically builds a new Docker container image, stores it securely, and updates the live website without any manual work or server management.
Packaging the Application with Docker
The 2048 game is a static web application made of HTML, CSS, and JavaScript files. To make sure it runs reliably in the cloud, it was packaged inside a lightweight Docker container using Nginx (a fast web server) running on Alpine Linux. This keeps the container small and allows it to start up in seconds. The initial container image was uploaded to a private storage registry called Amazon Elastic Container Registry (ECR).
Serverless Hosting on Amazon ECS Fargate
Instead of renting and managing traditional virtual servers (EC2 instances), the application is hosted on Amazon Elastic Container Service (ECS) using AWS Fargate. Fargate is a serverless compute engine that runs containers directly. A cluster and service were configured with 0.25 vCPU and 0.5 GB of memory, opening port 80 to the internet so users can play the game directly through the container's public IP address.
Connecting GitHub to AWS
To detect code changes automatically, the GitHub repository was linked to AWS using AWS Code Connections (via the official AWS GitHub App). This creates a secure webhook connection so that AWS is notified immediately whenever new commits are pushed to the main branch.
Automated Building with AWS CodeBuild
AWS CodeBuild acts as the automated build engine. Whenever triggered, it launches a temporary build environment, downloads the latest code from GitHub, builds a fresh Docker image, and tags it with both "latest" and the unique 7-character Git commit ID. It then pushes the new image to Amazon ECR and saves a small tracking file (imagedefinitions.json) into an Amazon S3 bucket so the deployment stage knows exact image details to use.
Orchestrating the Workflow with AWS CodePipeline
AWS CodePipeline ties the entire process together into three automated stages:
Source Stage: Pulls the newly pushed code from GitHub.
Build Stage: Runs AWS CodeBuild to compile the Docker image and push it to Amazon ECR.
Deploy Stage: Instructs Amazon ECS to update the live service. ECS performs a zero-downtime rolling update by launching a brand-new container task with the updated image, routing user traffic to it, and safely shutting down the old container task.
Security and Key Engineering Lessons
To keep the pipeline secure, a dedicated IAM service role was created following the principle of least privilege, restricting permissions strictly to the required ECR repository, S3 bucket, ECS service, and GitHub connection. During implementation, three critical configuration requirements were addressed:
Enabling Privileged Mode inside CodeBuild so it has permission to run Docker build commands.
Granting both modern (codeconnections) and legacy (codestar-connections) permissions in the IAM policy so CodeBuild can authenticate with GitHub during the source download phase.
Matching the exact container name between the build output file and the ECS task definition so automated deployments link properly.
