<?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 Bharatv on Medium]]></title>
        <description><![CDATA[Stories by Bharatv on Medium]]></description>
        <link>https://medium.com/@bharatv0009?source=rss-1f513febcd97------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GC8VnbK_iwR9Rr4B</url>
            <title>Stories by Bharatv on Medium</title>
            <link>https://medium.com/@bharatv0009?source=rss-1f513febcd97------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 15:02:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bharatv0009/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[From Code to Cloud: Deploying a Full-Stack App on AWS ECS using GitHub Actions (OIDC)]]></title>
            <link>https://medium.com/@bharatv0009/from-code-to-cloud-deploying-a-full-stack-app-on-aws-ecs-using-github-actions-oidc-5cc96c60168f?source=rss-1f513febcd97------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cc96c60168f</guid>
            <dc:creator><![CDATA[Bharatv]]></dc:creator>
            <pubDate>Mon, 06 Apr 2026 17:19:21 GMT</pubDate>
            <atom:updated>2026-04-06T17:19:21.567Z</atom:updated>
            <content:encoded><![CDATA[<p>Deploying applications manually is time-consuming, error-prone, and not scalable. In this guide, I’ll walk you through how I built a <strong>fully automated CI/CD pipeline</strong> to deploy a full-stack application (React + FastAPI) to AWS ECS using <strong>GitHub Actions and OIDC authentication</strong> — without storing any AWS access keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NsxaCfq-o0fGFYBb7a2S7Q.png" /></figure><h3>Overview</h3><p>The goal was simple: <br><em>Push code to GitHub → Automatically build → Deploy to AWS ECS → Run live application <br></em>And here’s the architecture that makes it happen:</p><pre>GitHub → GitHub Actions → Docker → Amazon ECR → Amazon ECS → Live App</pre><h3>Tech Stack</h3><ul><li><strong>Frontend</strong>: React (Vite)</li><li><strong>Backend</strong>: FastAPI</li><li><strong>Containerization</strong>: Docker</li><li><strong>CI/CD</strong>: GitHub Actions</li><li><strong>Cloud Services</strong>:</li><li>Amazon ECR (Container Registry)</li><li>Amazon ECS (Fargate for serverless containers)</li></ul><h3>Project Structure</h3><pre>project/<br> ├── backend/<br> ├── frontend/<br> ├── Dockerfile<br> ├── .dockerignore<br> └── .github/workflows/deploy.yml</pre><h3>Step 1: Dockerizing the Application</h3><p>To deploy efficiently, I created a <strong>multi-stage Docker build</strong>.</p><h4>Key idea:</h4><ul><li>Build frontend separately</li><li>Serve it via FastAPI backend</li></ul><pre># ---------- FRONTEND BUILD ----------<br>FROM node:22 AS frontend</pre><pre>WORKDIR /app/frontend<br>COPY frontend/ .<br>RUN npm install<br>RUN npm run build</pre><pre># ---------- BACKEND ----------<br>FROM python:3.10</pre><pre>WORKDIR /app</pre><pre>COPY backend/ ./backend<br>COPY backend/requirements.txt .</pre><pre>RUN pip install --no-cache-dir -r requirements.txt</pre><pre>COPY --from=frontend /app/frontend/dist ./frontend_dist</pre><pre>EXPOSE 8000</pre><pre>CMD [&quot;uvicorn&quot;, &quot;backend.main:app&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;, &quot;--port&quot;, &quot;8000&quot;]</pre><h3>Step 2: Backend Adjustments</h3><h4>Fix Imports</h4><pre>from backend.database import engine, Base, SessionLocal</pre><h4>Add __init__.py</h4><pre>touch backend/__init__.py</pre><h4>Serve Frontend via FastAPI</h4><pre>app.mount(&quot;/assets&quot;, StaticFiles(directory=&quot;frontend_dist/assets&quot;), name=&quot;assets&quot;)</pre><pre>@app.get(&quot;/&quot;)<br>def serve():<br>    return FileResponse(&quot;frontend_dist/index.html&quot;)</pre><h3>Step 3: Database Handling</h3><p>Initially, I faced issues connecting to a local PostgreSQL instance from ECS.</p><h4>Temporary solution:</h4><pre>DATABASE_URL = os.getenv(&quot;DATABASE_URL&quot;, &quot;sqlite:///./test.db&quot;)</pre><p>This allowed the app to run without external DB dependencies.</p><h3>Step 4: AWS Setup</h3><h4>1. Create ECR Repository</h4><ul><li>Store Docker images</li></ul><h4>2. ECS Configuration</h4><ul><li><strong>Cluster</strong>: Fargate</li><li><strong>Task Definition</strong>:</li><li>CPU: 256</li><li>Memory: 512</li><li>Port: 8000</li><li><strong>Service</strong>:</li><li>Desired tasks: 1</li><li>Public IP enabled</li></ul><h3>Step 5: Secure Authentication with OIDC</h3><p>Instead of storing AWS access keys in GitHub, I used <strong>OIDC (OpenID Connect)</strong>.</p><h4>Benefits:</h4><ul><li>No long-term credentials</li><li>More secure</li><li>Recommended by AWS</li></ul><h4>Steps:</h4><ol><li>Create OIDC provider in AWS</li><li>Create IAM Role for GitHub</li><li>Add trust policy:</li></ol><pre>&quot;Condition&quot;: {<br>  &quot;StringEquals&quot;: {<br>    &quot;token.actions.githubusercontent.com:aud&quot;: &quot;sts.amazonaws.com&quot;<br>  },<br>  &quot;StringLike&quot;: {<br>    &quot;token.actions.githubusercontent.com:sub&quot;: &quot;repo:&lt;your-repo&gt;:*&quot;<br>  }<br>}</pre><h3>Step 6: GitHub Actions CI/CD Pipeline</h3><p>File: .github/workflows/deploy.yml</p><pre>name: Deploy to ECS</pre><pre>on:<br>  push:<br>    branches:<br>      - main</pre><pre>permissions:<br>  id-token: write<br>  contents: read</pre><pre>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest</pre><pre>    steps:<br>      - name: Checkout<br>        uses: actions/checkout@v4</pre><pre>      - name: Configure AWS (OIDC)<br>        uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          role-to-assume: &lt;IAM_ROLE_ARN&gt;<br>          aws-region: ap-south-1</pre><pre>      - name: Login to ECR<br>        uses: aws-actions/amazon-ecr-login@v2</pre><pre>      - name: Build &amp; Push Image<br>        run: |<br>          docker build -t ${{ secrets.ECR_REPOSITORY }}:latest .<br>          docker push ${{ secrets.ECR_REPOSITORY }}:latest</pre><pre>      - name: Deploy to ECS<br>        run: |<br>          aws ecs update-service \<br>            --cluster ${{ secrets.ECS_CLUSTER }} \<br>            --service ${{ secrets.ECS_SERVICE }} \<br>            --desired-count 1 \<br>            --force-new-deployment</pre><h3>Step 7: GitHub Secrets</h3><p>Store these in your repo:</p><pre>ECR_REPOSITORY<br>ECS_CLUSTER<br>ECS_SERVICE</pre><h3>Step 8: Access Your Application</h3><ol><li>Go to ECS → Cluster → Service → Tasks</li><li>Copy Public IP</li><li>Open in browser:</li></ol><pre>http://&lt;public-ip&gt;:8000</pre><h3>Challenges Faced (and Fixes)</h3><h4>Node version issues</h4><p>✔ Fixed by upgrading to Node 22</p><h4>Import errors</h4><p>✔ Added __init__.py and corrected paths</p><h4>Database connection failure</h4><p>✔ Switched temporarily to SQLite</p><h4>ECS tasks stopping</h4><p>✔ Debugged using CloudWatch logs</p><h4>OIDC not working</h4><p>✔ Added:</p><pre>permissions:<br>  id-token: write</pre><h3>Final Outcome</h3><ul><li>Fully automated CI/CD pipeline</li><li>Secure AWS authentication (OIDC)</li><li>Dockerized full-stack application</li><li>Deployed on ECS Fargate</li><li>Accessible via public IP</li></ul><h3>Future Improvements</h3><ul><li>Use <strong>Amazon RDS</strong> instead of SQLite</li><li>Add <strong>Application Load Balancer (ALB)</strong></li><li>Configure <strong>custom domain + HTTPS (Route53 + ACM)</strong></li><li>Implement <strong>blue/green deployments</strong></li></ul><h3>Final Thoughts</h3><p>This project helped me understand not just deployment, but <strong>production-grade DevOps practices</strong> — especially secure authentication with OIDC and container-based deployments.</p><p>If you’re building modern cloud-native apps, this setup is a <strong>great starting point</strong>.</p><p><em>If you found this helpful, feel free to share or connect — always happy to discuss DevOps and cloud engineering!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cc96c60168f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>