<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali Zaib</title>
    <description>The latest articles on DEV Community by Ali Zaib (@ali_zaib_c01cd62f030d446f).</description>
    <link>https://dev.to/ali_zaib_c01cd62f030d446f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4257004%2Ff957a0c8-b719-49df-a10e-d27aabb8b2bb.jpg</url>
      <title>DEV Community: Ali Zaib</title>
      <link>https://dev.to/ali_zaib_c01cd62f030d446f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ali_zaib_c01cd62f030d446f"/>
    <language>en</language>
    <item>
      <title>Building a Fully Automated CI/CD Pipeline on AWS with Docker, ECR, CodeBuild, CodePipeline and ECS Fargate</title>
      <dc:creator>Ali Zaib</dc:creator>
      <pubDate>Sat, 21 Nov 2026 09:15:54 +0000</pubDate>
      <link>https://dev.to/ali_zaib_c01cd62f030d446f/building-a-fully-automated-cicd-pipeline-on-aws-with-docker-ecr-codebuild-codepipeline-and-ecs-3753</link>
      <guid>https://dev.to/ali_zaib_c01cd62f030d446f/building-a-fully-automated-cicd-pipeline-on-aws-with-docker-ecr-codebuild-codepipeline-and-ecs-3753</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Shipping software by hand is one of the quickest ways to introduce mistakes. Someone builds an image on their laptop, pushes it to a registry, logs into a console and clicks through a deployment. It works until the day a step is skipped, a wrong tag is deployed or the one person who knows the process is on leave.&lt;/p&gt;

&lt;p&gt;Continuous Integration and Continuous Delivery (CI/CD) solves this by turning the release process into code that runs the same way every time. In this project I built a complete CI/CD pipeline on AWS that takes a change from a &lt;code&gt;git push&lt;/code&gt; to a running container on &lt;strong&gt;Amazon ECS Fargate&lt;/strong&gt;, with no manual steps in between.&lt;/p&gt;

&lt;p&gt;To keep the focus on the pipeline rather than the application, I used the classic &lt;strong&gt;2048 game&lt;/strong&gt; as the workload. It is a static web app that is easy to containerize, and it gives an instantly visible result whenever a deployment succeeds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Credit:&lt;/strong&gt; the application source and project outline come from the &lt;a href="https://github.com/techwithlucy/ztc-projects" rel="noopener noreferrer"&gt;ZTC projects&lt;/a&gt; learning repository. The AWS setup, IAM configuration and pipeline were built and verified by me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At a glance&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Time: about 2 to 3 hours&lt;/li&gt;
&lt;li&gt;Cost: about $1 or less&lt;/li&gt;
&lt;li&gt;Result: every push to &lt;code&gt;main&lt;/code&gt; is built, stored in ECR and deployed to ECS automatically&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the pipeline does
&lt;/h2&gt;

&lt;p&gt;Whenever I push code to GitHub, three things happen automatically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Source:&lt;/strong&gt; CodePipeline detects the push and fetches the latest code from GitHub.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build:&lt;/strong&gt; CodeBuild runs the instructions in &lt;code&gt;buildspec.yml&lt;/code&gt;. It builds a Docker image, tags it, pushes it to Amazon ECR and produces a small file called &lt;code&gt;imagedefinitions.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy:&lt;/strong&gt; CodePipeline hands that file to Amazon ECS, which replaces the running container with the new image.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkaz6kb2pmxoxs5eqbfo8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkaz6kb2pmxoxs5eqbfo8.png" alt=" " width="799" height="318"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Architecture diagram of the CI/CD pipeline&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Tech stack and why each piece is there
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Service&lt;/th&gt;
&lt;th&gt;Role in the project&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Stores the source code and triggers the pipeline on every push&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Docker + Nginx&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Packages the app so it runs identically everywhere&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Amazon ECR&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Private registry that stores the Docker images&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AWS CodeBuild&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Managed build server that builds and pushes the image&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Amazon S3&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Holds the build artifacts passed between stages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AWS CodePipeline&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Orchestrates Source, Build and Deploy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Amazon ECS (Fargate)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Runs the container without any servers to manage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;IAM&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Gives each service only the access it needs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I chose &lt;strong&gt;Fargate&lt;/strong&gt; because it removes server management completely. There are no EC2 instances to patch or scale, so the pipeline is the only moving part, which is exactly what I wanted to learn.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Containerize the application
&lt;/h2&gt;

&lt;p&gt;The Dockerfile is intentionally small. It uses the official Nginx image, copies the game files into Nginx's web root and starts Nginx in the foreground so the container keeps running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; nginx:latest
&lt;span class="k"&gt;COPY&lt;/span&gt; . /usr/share/nginx/html
&lt;span class="k"&gt;EXPOSE&lt;/span&gt; 80
&lt;span class="k"&gt;CMD&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;, &lt;span class="s2"&gt;"-g"&lt;/span&gt;, &lt;span class="s2"&gt;"daemon off;"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I built it locally first. Testing the container on my own machine before touching AWS means any problem at this stage is a Docker problem, not a cloud problem, which makes it much easier to diagnose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t 2048-game .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe3zrnz9hae03p4irq46t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe3zrnz9hae03p4irq46t.png" alt=" " width="799" height="438"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Docker image building successfully&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Store the image in Amazon ECR
&lt;/h2&gt;

&lt;p&gt;Next I created a private repository in Amazon ECR. This is where CodeBuild will later push every new version of the image, and where ECS will pull it from.&lt;/p&gt;

&lt;p&gt;To push the image I tagged it with the repository URI, authenticated Docker with a temporary ECR login token and pushed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker tag 2048-game:latest &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;ECR_URI&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;:latest

aws ecr get-login-password --region &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;your-region&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; docker login --username AWS --password-stdin &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;ECR_URI&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

docker push &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;ECR_URI&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The image appeared in the repository straight away.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2dshbvxiiyj5exmxyps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2dshbvxiiyj5exmxyps.png" alt=" " width="800" height="131"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Image stored in the ECR repository&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Deploy manually to ECS Fargate first
&lt;/h2&gt;

&lt;p&gt;Before automating anything, I deployed the container by hand. This is the most useful habit I took from the project: &lt;strong&gt;if it does not work manually, a pipeline will only automate the failure.&lt;/strong&gt; Having a known-good manual deployment also gives you something to compare against when the pipeline misbehaves.&lt;/p&gt;

&lt;p&gt;The manual deployment had four parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cluster:&lt;/strong&gt; a logical group for my tasks, created with the AWS Fargate (serverless) option.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Task definition:&lt;/strong&gt; the blueprint for the container. It names the container (&lt;code&gt;2048-container&lt;/code&gt;), points to the ECR image and maps port 80 to port 80.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service:&lt;/strong&gt; keeps the desired number of tasks (one) running and replaces any that stop. I placed it in the default VPC and enabled a public IP.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security group:&lt;/strong&gt; allows inbound HTTP on port 80, otherwise the browser cannot reach the container.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqzzjldwourl3vxtfskwm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqzzjldwourl3vxtfskwm.png" alt=" " width="799" height="233"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;ECS cluster created successfully&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the task was running, I opened its public IP in a browser and the game loaded. That confirmed the image, the task definition, the networking and the security group were all correct.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fizuolaie3tbzhnzasvmd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fizuolaie3tbzhnzasvmd.png" alt=" " width="800" height="429"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;The 2048 game served from the container on ECS&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Create my own GitHub repository
&lt;/h2&gt;

&lt;p&gt;CodePipeline needs a repository I control so it can listen for pushes, so I created a new repository and pushed the project to it, along with a &lt;code&gt;buildspec.yml&lt;/code&gt; in the root.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git add .
git commit -m &lt;span class="s2"&gt;"Initial commit"&lt;/span&gt;
git remote add origin &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;your-repository-url&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
git branch -M main
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmglmxz3dlr0xxzgpc415.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmglmxz3dlr0xxzgpc415.png" alt=" " width="800" height="342"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;GitHub repository with the Dockerfile, buildspec.yml and game source&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5: Write the buildspec (the heart of CI)
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;buildspec.yml&lt;/code&gt; tells CodeBuild exactly what to do. It has three phases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;pre_build:&lt;/strong&gt; logs in to ECR so the build can push images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;build:&lt;/strong&gt; builds the Docker image and tags it with the ECR repository URI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;post_build:&lt;/strong&gt; pushes the image and writes &lt;code&gt;imagedefinitions.json&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;

&lt;span class="na"&gt;phases&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pre_build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"echo Logging in to Amazon ECR..."&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"aws ecr get-login-password --region &amp;lt;your-region&amp;gt; | docker login --username AWS --password-stdin &amp;lt;ECR_URI&amp;gt;"&lt;/span&gt;

  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"echo Building the Docker image..."&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"docker build -t 2048-game ."&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"docker tag 2048-game:latest &amp;lt;ECR_URI&amp;gt;:latest"&lt;/span&gt;

  &lt;span class="na"&gt;post_build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"echo Pushing the Docker image to Amazon ECR..."&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"docker push &amp;lt;ECR_URI&amp;gt;:latest"&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"echo Creating imagedefinitions.json for ECS deployment..."&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'printf ''[{"name":"2048-container","imageUri":"%s"}]'' "&amp;lt;ECR_URI&amp;gt;:latest" &amp;gt; imagedefinitions.json'&lt;/span&gt;

&lt;span class="na"&gt;artifacts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;imagedefinitions.json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The most important detail is &lt;code&gt;imagedefinitions.json&lt;/code&gt;. It is the bridge between CodeBuild and ECS: it tells the ECS deploy action &lt;strong&gt;which container to update and which image to use&lt;/strong&gt;. The &lt;code&gt;name&lt;/code&gt; value must match the container name in the task definition exactly, otherwise the Deploy stage fails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frsjfvdwfcrhdvsfa6rw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frsjfvdwfcrhdvsfa6rw9.png" alt=" " width="800" height="235"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;buildspec.yml configured with my region, repository and container name&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 6: Set up permissions with IAM
&lt;/h2&gt;

&lt;p&gt;AWS services cannot act on each other by default, so CodeBuild needs an IAM role. I created &lt;code&gt;codeBuildServiceRole&lt;/code&gt; with CodeBuild as the trusted entity and attached managed policies for ECR, CodeBuild and S3.&lt;/p&gt;

&lt;p&gt;Then I added a small inline policy that lets CodeBuild update only my ECS service, rather than every service in the account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"ecs:UpdateService"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ecs:DescribeServices"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;ECS_SERVICE_ARN&amp;gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This inline policy is a small example of &lt;strong&gt;least privilege&lt;/strong&gt;: grant the narrowest permission that gets the job done. For a production setup I would tighten the managed policies the same way (more on that below).&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Create the S3 bucket and CodeBuild project
&lt;/h2&gt;

&lt;p&gt;CodeBuild produces output such as &lt;code&gt;imagedefinitions.json&lt;/code&gt;, so I created an S3 bucket to hold build artifacts. Then I created the CodeBuild project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Source: my GitHub repository, connected through an OAuth app credential managed by CodeBuild&lt;/li&gt;
&lt;li&gt;Service role: the existing &lt;code&gt;codeBuildServiceRole&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Build instructions: use the &lt;code&gt;buildspec.yml&lt;/code&gt; file from the repository&lt;/li&gt;
&lt;li&gt;Artifacts: stored in the S3 bucket&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before building the pipeline I triggered a build manually. Testing each stage on its own meant that when the full pipeline ran, any failure would be easy to place. The build succeeded, the image was pushed to ECR and &lt;code&gt;imagedefinitions.json&lt;/code&gt; appeared in S3.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqtzest3tb5xomzr3ai0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqtzest3tb5xomzr3ai0q.png" alt=" " width="800" height="200"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;&lt;code&gt;imagedefinitions.json&lt;/code&gt; stored in the S3 artifact bucket&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 8: Connect everything with CodePipeline
&lt;/h2&gt;

&lt;p&gt;Finally I created the pipeline, &lt;code&gt;2048-game-pipeline&lt;/code&gt;, with three stages:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stage&lt;/th&gt;
&lt;th&gt;Provider&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Source&lt;/td&gt;
&lt;td&gt;GitHub (OAuth app)&lt;/td&gt;
&lt;td&gt;Starts the pipeline when &lt;code&gt;main&lt;/code&gt; changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build&lt;/td&gt;
&lt;td&gt;AWS CodeBuild&lt;/td&gt;
&lt;td&gt;Runs &lt;code&gt;buildspec.yml&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deploy&lt;/td&gt;
&lt;td&gt;Amazon ECS&lt;/td&gt;
&lt;td&gt;Updates &lt;code&gt;2048-service&lt;/code&gt; using &lt;code&gt;imagedefinitions.json&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I skipped the optional Test stage for this project. CodePipeline created its own service role, and the first run started immediately.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F49x4ym648zrsn8yme1jb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F49x4ym648zrsn8yme1jb.png" alt=" " width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;CodePipeline created with Source, Build and Deploy stages&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each stage turned green in turn, ending with a successful deployment to ECS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvldseowtku9y9awp2d4m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvldseowtku9y9awp2d4m.png" alt=" " width="799" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Deploy stage succeeded&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 9: The real test, a code change
&lt;/h2&gt;

&lt;p&gt;A pipeline only proves itself when a change flows through it untouched. I edited the heading in &lt;code&gt;index.html&lt;/code&gt; to "2048 by Me", then ran just three commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add .
git commit -m &lt;span class="s2"&gt;"Changed game name to 2048 by Me"&lt;/span&gt;
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was the only manual action. The push triggered the pipeline, CodeBuild built and pushed a fresh image, and ECS started a new task. The ECS console shows the old tasks stopped and the new one running: a &lt;strong&gt;rolling deployment&lt;/strong&gt; that replaces the container without me touching the console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxwafq92l8jbe2img4fl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxwafq92l8jbe2img4fl4.png" alt=" " width="800" height="193"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;ECS showing the new task running and older tasks stopped&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Reloading the public IP showed the updated title.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F43vgyncevznuzx89yaeq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F43vgyncevznuzx89yaeq.png" alt=" " width="800" height="442"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;The updated game live on ECS Fargate&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Common problems and how to fix them
&lt;/h2&gt;

&lt;p&gt;If you build this yourself, these are the places it most often goes wrong:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Build fails at the ECR login or push:&lt;/strong&gt; the CodeBuild role is missing ECR permissions, or the region or repository URI in &lt;code&gt;buildspec.yml&lt;/code&gt; is wrong.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy stage fails:&lt;/strong&gt; the container &lt;code&gt;name&lt;/code&gt; in &lt;code&gt;imagedefinitions.json&lt;/code&gt; does not match the task definition's container name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Site does not load on the public IP:&lt;/strong&gt; the security group does not allow inbound port 80, or the service does not have a public IP enabled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CodeBuild cannot update the service:&lt;/strong&gt; the inline policy's resource ARN does not match your ECS service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pipeline does not trigger on push:&lt;/strong&gt; the Source stage is pointing at a different repository or branch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In almost every case the answer was in the CodeBuild logs or the failed stage's details, so read those first.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Automate last.&lt;/strong&gt; Get the manual deployment working, then automate it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;imagedefinitions.json&lt;/code&gt; is the contract&lt;/strong&gt; between the build and the deployment. Small mismatches here cause the most confusing failures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM is where most pipeline problems hide.&lt;/strong&gt; Understanding which service needs which permission is half the work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test each stage in isolation&lt;/strong&gt; before chaining them together.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fargate keeps the focus on delivery,&lt;/strong&gt; since there are no servers to look after.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How I would harden this for production
&lt;/h2&gt;

&lt;p&gt;This project is designed for learning. For a real workload I would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace broad managed policies such as &lt;code&gt;AmazonS3FullAccess&lt;/code&gt; with &lt;strong&gt;least-privilege, resource-scoped policies&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Pin the base image to a &lt;strong&gt;specific version&lt;/strong&gt; instead of &lt;code&gt;nginx:latest&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Tag images with the &lt;strong&gt;commit SHA&lt;/strong&gt; as well as &lt;code&gt;latest&lt;/code&gt;, so any release can be traced and rolled back.&lt;/li&gt;
&lt;li&gt;Add a &lt;strong&gt;Test stage&lt;/strong&gt; with linting and ECR image scanning before deployment.&lt;/li&gt;
&lt;li&gt;Put an &lt;strong&gt;Application Load Balancer&lt;/strong&gt; in front of the service for a stable DNS name, HTTPS and health checks.&lt;/li&gt;
&lt;li&gt;Define all of the infrastructure as code with &lt;strong&gt;Terraform or CloudFormation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Use a &lt;strong&gt;GitHub App connection (CodeConnections)&lt;/strong&gt; instead of the OAuth app, which AWS no longer recommends.&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;automatic rollback&lt;/strong&gt; and add CloudWatch alarms.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cost and cleanup
&lt;/h2&gt;

&lt;p&gt;The whole project cost about $1 or less. To avoid ongoing charges, delete the resources when you are done: the pipeline, the CodeBuild project, the IAM roles and policies, the S3 bucket, the ECR repository, and finally the ECS service and cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;A single &lt;code&gt;git push&lt;/code&gt; now takes code from my laptop to a running, containerized service on AWS, with no manual steps in between. The project gave me practical experience with the services that make up a real cloud delivery workflow and, more importantly, with how they depend on each other through IAM, artifacts and configuration.&lt;/p&gt;

&lt;p&gt;Next, I plan to rebuild the same pipeline with Terraform and add an Application Load Balancer with HTTPS.&lt;/p&gt;

&lt;p&gt;If you have built something similar or have suggestions, I would love to hear about it in the comments.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Connect with me:&lt;/strong&gt; &lt;a href="//www.linkedin.com/in/ali-zaib"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cicd</category>
      <category>devops</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
