<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Iriondo on Medium]]></title>
        <description><![CDATA[Stories by David Iriondo on Medium]]></description>
        <link>https://medium.com/@davidiriondopalacios?source=rss-7cb6778b2d59------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*omJdE8QGDkkDu56DMbG7tA.jpeg</url>
            <title>Stories by David Iriondo on Medium</title>
            <link>https://medium.com/@davidiriondopalacios?source=rss-7cb6778b2d59------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:54:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@davidiriondopalacios/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Serverless CI/CD Pipeline on AWS with Github Actions and Terraform]]></title>
            <link>https://medium.com/@davidiriondopalacios/building-a-serverless-ci-cd-pipeline-on-aws-with-github-actions-and-terraform-dae596f1d2e0?source=rss-7cb6778b2d59------2</link>
            <guid isPermaLink="false">https://medium.com/p/dae596f1d2e0</guid>
            <category><![CDATA[serverless-architecture]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[aws-ecs-fargate]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[David Iriondo]]></dc:creator>
            <pubDate>Fri, 02 Jan 2026 19:58:14 GMT</pubDate>
            <atom:updated>2026-01-03T17:04:22.436Z</atom:updated>
            <content:encoded><![CDATA[<p>The more I work with Kubernetes and Jenkins, the more I understand that, for most projects, their complexity is not justified. I mean… yes, kubernetes and jenkins are extremely powerful, but it can also be complex to manage and maintain especially for small teams or early stage products IMO.</p><p>This project demonstrates a different approach: a fully serverless CI/CD pipeline built with Github Actions and AWS managed container services. By relying on managed infrastructure, teams can reduce operational overhead and focus on delivering features faster</p><h4>High-Level Architecture</h4><p>The system is composed of three main parts:</p><ul><li>CI/CD pipelines powered by GitHub Actions</li><li>Infrastructure provisioned with Terraform</li><li>Containerized applications running on AWS ECS (Fargate)</li></ul><p>Before I forget, I’ve used <strong>OpenID Connection</strong> to connect Github and AWS with out secrets stored in ithub. This <a href="https://dev.to/aws-builders/securely-connect-github-actions-to-aws-using-iam-roles-and-oidc-4ek2"><strong>post</strong></a> was usefully to me to achieve this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5slTK0yGXibQgRoWCzCG6w.png" /></figure><h4>Application Context</h4><p>To give this project real context we going to deploy two applications:</p><p>Frontend</p><ul><li>Built with <a href="https://preactjs.com/">Preact</a> (no special reason I just like this framework)</li><li>Deployed as a containerized service</li><li>Communicates with the backend through an API</li></ul><p>Backend</p><ul><li>Built with <a href="https://fastapi.tiangolo.com/">FastAPI</a> (easy framework to build API’s)</li><li>Runs with two ECS tasks behind an ALB</li><li>Each request can be handled by either instance, depending on load balancing</li></ul><p>And last but not least, <strong>AWS Application Infrastructure Architecture</strong></p><p>The goal is to provide a realistic but minimal infrastructure that supports high availability and automated deployments without introducing unnecessary operational complexity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*grcuVi6K_6cIBbXtbt_fsw.png" /></figure><p>After this introduction, it’s time to build the serverless CI/CD infrastructure</p><p>Before starting, make sure you have the <strong>AWS CLI installed and configured</strong>, and that you are logged in with a user that has enough permissions to create and manage AWS resources such as VPC, ECS, ECR, IAM, and ALB, etc</p><blockquote>Friendly advice:<em><br> To keep things simple I recommend using an AWS user with the </em><em>AdministratorAccess policy, just for learning and demo purposes</em></blockquote><h4>Project Repositories</h4><p>The project is split into three repositories</p><p><strong>Terraform Infrastructure</strong><br>Contains all the Terraform code required to provision AWS resources.</p><p><strong>Frontend</strong><br>A Preact application deployed as a containerized service on ECS.</p><p><strong>Backend</strong><br>A FastAPI application running as a containerized service behind an Application Load Balancer.</p><p>Each repository, except terraform infraestructure, has its own CI/CD workflow powered by GitHub Actions.</p><h4>Terraform Infrastructure Overview</h4><p>I assume you already have some basic knowledge of Terraform. If not, don’t worry, you can still reproduce the project without diving into every line of code.</p><p>Instead of copying and pasting the entire Terraform configuration, here is a brief overview of the structure and what you will find inside the infrastructure repository.</p><p>The infrastructure is split into logical modules</p><pre>├── code<br>│   ├── main.tf<br>│   ├── modules<br>│   │   ├── cluster (ECS, ALB, Task definition, ECS Service, CLoudWatch)<br>│   │   │   ├── main.tf<br>│   │   │   ├── outputs.tf<br>│   │   │   └── variables.tf<br>│   │   ├── compute (ECR)<br>│   │   │   ├── main.tf<br>│   │   │   ├── outputs.tf<br>│   │   │   └── variables.tf<br>│   │   ├── network (VPC,Subnet, NAT, IGW, Route table, ...)<br>│   │   │   ├── main.tf<br>│   │   │   ├── outputs.tf<br>│   │   │   └── variables.tf<br>│   │   └── security (Roles, Policies, Security groups, ...)<br>│   │       ├── main.tf<br>│   │       ├── outputs.tf<br>│   │       └── variables.tf<br>│   ├── outputs.tf<br>│   ├── templates (Container definition template)<br>│   │   └── container_definition.json<br>│   ├── terraform.tf (backend s3)<br>│   └── variables.tf<br>├── README.md<br>└── terraform.tfstate</pre><p><strong>Terraform State Backend (S3)</strong></p><p>This project expects you to have an S3 bucket already created to store the Terraform state remotely.</p><p>You can create the bucket using the AWS CLI:</p><pre>aws s3api create-bucket \<br>  --bucket your-bucket-name \<br>  --region eu-north-1 \<br>  --create-bucket-configuration LocationConstraint=eu-north-1</pre><p>Enable versioning on the bucket:</p><pre>aws s3api put-bucket-versioning \<br>  --bucket your-bucket-name \<br>  --versioning-configuration Status=Enabled</pre><p>If you don’t want to store the Terraform state in S3, you can comment out the backend configuration located in code/terraform.tf:</p><pre>backend &quot;s3&quot; {<br>    bucket = &quot;your-bucket-name&quot;<br>    key    = &quot;terraform.tfstate&quot;<br>    region = &quot;eu-north-1&quot;<br>  }</pre><h4>Create the infrastructure</h4><p>Move into <em>/code</em> directory and initialize Terraform</p><pre>terraform init</pre><p>Then apply terraform plan to create infraestructure</p><pre>terraform apply -var=&quot;github_owner={Your_github_organization}&quot;</pre><p>Once Terraform finishes, you will see several output values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*xZEOeq8E04sdGq5-ed90gg.png" /></figure><p>The most importants are:</p><ul><li>application_url<em>: </em>Public<em> </em>URL to access the application(HTTP not HTTPS)</li><li>github_actions_role_irn<em>: </em>IAM role used by GitHub Actions</li></ul><p>At this point the infrastructure is created but it’s not fully operational yet.</p><p><strong>Circular Dependency Between Infrastructure and CI/CD</strong></p><p>ECS services require container images to run, but ECR repositories don’t contain images yet, and CI/CD needs the cluster to deploy the containers. This creates a circular dependency between infrastructure and CI/CD.</p><p>There are two ways to solve this:</p><p>Split the infrastructure creation into multiple steps</p><ul><li>Create everything except ECS</li><li>Push images to ECR via GitHub Actions</li><li>Run Terraform again to create ECS services</li></ul><p>Use dummy container images initially</p><ul><li>Deploy ECS services with placeholder images</li><li>Replace them later with real application images</li></ul><p>For this project, I chose the <strong>second approach</strong>, as it keeps the setup simpler for demonstration purposes.</p><p>I wanted to mention this explicitly because it’s a real world problem you could eventually encounter when working with ECS and Terraform.</p><h4>Verifying Resources in AWS</h4><p>At this point, I recommend go to AWS console and exploring the resources Terraform has created:</p><ul><li>ECS Cluster</li><li>ECS Services</li><li>ECR Repositories</li><li>Application Load Balancer (ALB)</li><li>IAM Roles</li><li>VPC and networking resources</li><li>…</li></ul><p>All resources are prefixed with <strong>scc</strong> (serverless ci cd), for example:</p><ul><li>scc-vpc</li><li>scc-cluster</li></ul><p>This makes it easy to identify everything related to the project.</p><h4>Github Action CI/CD</h4><p>Next, fork both the <strong>frontend</strong> and <strong>backend</strong> repositories.<br> Both repositories use the same Github Actions workflow configuration, which is triggered only on the main branch.</p><pre>name: CI - Build &amp; Test &amp; Quality (Develop)<br>run-name: CI run by ${{ github.actor }} on develop<br>on:<br>  push:<br>    branches: [main]</pre><pre>permissions:<br>  contents: read<br>  id-token: write</pre><pre>jobs:<br>  build_test_and_quality:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Check out<br>        uses: actions/checkout@v6</pre><pre>      - name: Set up python 3.12<br>        uses: actions/setup-python@v6<br>        with:<br>          python-version: &quot;3.12&quot;</pre><pre>      - name: Install project packages<br>        run: pip install -r requirements.txt</pre><pre>      - name: Run test<br>        run: pytest</pre><pre>      - name: Configure AWS credentials<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          aws-region: eu-north-1<br>          role-to-assume: {github_actions_role_irn} &lt;-- REMEMBER THIS VALUE?<br>          audience: sts.amazonaws.com</pre><pre>      - name: Login to Amazon ECR<br>        id: login-ecr<br>        uses: aws-actions/amazon-ecr-login@v2</pre><pre>      - name: Build, tag, and push docker image to Amazon ECR<br>        id: build-and-push<br>        env:<br>          REGISTRY: ${{ steps.login-ecr.outputs.registry }}<br>          REPOSITORY: scc-backend<br>          IMAGE_TAG: ${{ github.sha }}<br>        run: |<br>          IMAGE_URI=&quot;$REGISTRY/$REPOSITORY:$IMAGE_TAG&quot;<br>          docker build -t $IMAGE_URI .<br>          docker push $IMAGE_URI<br>          echo &quot;image_uri=$IMAGE_URI&quot; &gt;&gt; $GITHUB_OUTPUT</pre><pre>      - name: Download task definition<br>        run: |<br>          aws ecs describe-task-definition --task-definition scc-backend-task --query &quot;taskDefinition&quot; --output json &gt; task-definition.json</pre><pre>      - name: Fill in new image ID in task definition<br>        id: task-def<br>        uses: aws-actions/amazon-ecs-render-task-definition@v1<br>        with:<br>          task-definition: task-definition.json<br>          container-name: scc-backend<br>          image: ${{ steps.build-and-push.outputs.image_uri }}</pre><pre>      - name: Deploy Amazon ECS task definition<br>        uses: aws-actions/amazon-ecs-deploy-task-definition@v1<br>        with:<br>          task-definition: ${{ steps.task-def.outputs.task-definition }}<br>          service: scc-backend-service<br>          cluster: scc-cluster</pre><p>Before diving into the workflow pay close attention to this line:</p><pre>role-to-assume: {github_actions_role_irn}</pre><p>Dou you remember? This value comes directly from the Terraform output we saw earlier. You must copy that ARN and paste it here so Github knows <strong>which AWS IAM role to assume</strong> when calling AWS APIs.</p><h4>CI/CD Workflow Summary</h4><p><strong>Continuous Integration (CI)</strong></p><ul><li>Install dependencies</li><li>Run tests</li><li>Build Docker images</li><li>Authenticate with AWS</li><li>Push images to ECR</li></ul><p><strong>Continuous Delivery (CD)</strong></p><ul><li>Download the ECS task definition</li><li>Update it with the new image version</li><li>Register a new task definition revision</li><li>Deploy the updated service to ECS</li></ul><h4>Running the Application</h4><p>Once the workflow is configured, push any change to the main branch.</p><p>Go to the <strong>Actions</strong> tab in your repository, and you’ll see the pipeline running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*SYs_HngGtKEhkKvtlbdLQw.png" /></figure><p>In the AWS Console, you will see ECS deploying the new task definitions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZUlTvqfx8MMJ74oyoOE8A.png" /></figure><p>Under <strong>Deployments and tasks </strong>column you will notice :</p><ul><li>2 backend tasks running</li><li>1 frontend task running</li></ul><p>If you click in <strong>scc-backend-service</strong> you will see two tasks running with the latest task definition version. In my case <strong>version 6</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UEVUIEQlKjnZZP__oWJCRw.png" /></figure><h4>Test the application</h4><p>Remember the <strong>application_url</strong> Terraform output?</p><p>In my case:</p><pre>application_url = &quot;scc-alb-1070888571.eu-north-1.elb.amazonaws.com&quot;</pre><p>This URL exposes the application to the internet. And remember its HTTP not HTTPS</p><p>When you open it, you’ll see this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*vgf2FLLPLBsmiNHh3WiOAA.png" /></figure><p>The dashboard communicates with the backend API.<br> Each backend instance is identified by a unique instance_id.</p><p>If you press <strong>refresh button</strong> , you’ll notice different instances respondin, confirming that the ALB is correctly load balancing traffic across backend replicas.</p><p>I strongly encourage you to:</p><ul><li>Modify the backend</li><li>Add new API endpoints</li><li>Extend the frontend</li><li>Push changes frequently</li></ul><p>Watching CI/CD take your code from local to production is the whole point of this project :)</p><h4>Just for the record</h4><p>I’ve spend 2 weeks to complete this project and a total cost of 11.26$, I didn’t expect this bill to be honest</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*2846-_SmKVV15GJcL82Hdw.png" /></figure><p><strong>Moral of the history</strong></p><p>Always shut down your infrastructure when you’re not using it unless you enjoy surprise AWS bills 😅</p><p><strong>And that’s all, thanks a lot for your time</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*XuwPkgDI9sXLIFkp2hbyGQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dae596f1d2e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>