<?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: Michael Villaverde</title>
    <description>The latest articles on DEV Community by Michael Villaverde (@mbvillaverde).</description>
    <link>https://dev.to/mbvillaverde</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2988992%2F302326a5-e870-4da9-8b43-12ac8c6e2c6d.jpg</url>
      <title>DEV Community: Michael Villaverde</title>
      <link>https://dev.to/mbvillaverde</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mbvillaverde"/>
    <language>en</language>
    <item>
      <title>How I made my Home Server accessible outside my home</title>
      <dc:creator>Michael Villaverde</dc:creator>
      <pubDate>Thu, 01 May 2025 14:16:37 +0000</pubDate>
      <link>https://dev.to/mbvillaverde/how-i-made-my-home-server-accessible-outside-my-home-2i9b</link>
      <guid>https://dev.to/mbvillaverde/how-i-made-my-home-server-accessible-outside-my-home-2i9b</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"Every developer should try to self host at least once" - &lt;em&gt;anonymous&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I recall seeing a similar sentiment pop up on Reddit months ago, and it genuinely sparked a feeling of FOMO – a worry that I was missing out on something important. Despite working in this industry for a considerable time, I haven’t yet explored setting up my own home server.&lt;/p&gt;

&lt;p&gt;Currently, I rely on services like Google Drive, Dropbox, and iCloud for file backups, which are convenient, but I recognize that we’re essentially entrusting our data to these companies and I'm now considering the potential benefits of taking control of my data by exploring home server options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Then the journey begins...
&lt;/h2&gt;

&lt;p&gt;I bought a barebone Mini PC since I have spare laptop RAM and NVME SSD lying around my house. I then downloaded &lt;a href="https://ubuntu.com/download/server" rel="noopener noreferrer"&gt;Ubuntu Server&lt;/a&gt; and use &lt;a href="https://etcher.balena.io/" rel="noopener noreferrer"&gt;Balena Etcher&lt;/a&gt; to flash the ISO image into my flash drive.&lt;/p&gt;

&lt;p&gt;The setup begins by connecting a monitor, keyboard and ethernet cable for internet access in the PC and installing the operating system. There are many tutorials online on how to perform this tasks but I am pretty sure you already know how to do these things. After installation and logging in, I ran the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will help you remotely access your machine so that you can remove the keyboard and the monitor connected into it (In my case, I am using those things for my work laptop 😂). You can also enable &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;https&lt;/code&gt; in order to access your server in your preferred browser of choice.&lt;/p&gt;

&lt;p&gt;I chose &lt;a href="https://casaos.zimaspace.com/" rel="noopener noreferrer"&gt;Casa OS&lt;/a&gt; to run my home server dashboard and applications. It is a community based open source software that is also very beginner friendly, which is ideal for users like me. In order to install it, just run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://get.casaos.io | &lt;span class="nb"&gt;sudo &lt;/span&gt;bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Casa OS by default runs on port 80, but you can always change the port using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;wget &lt;span class="nt"&gt;-qLO&lt;/span&gt; - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/change-casaos-web-ui-port/run.sh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing Casa OS, access your dashboard in your preferred browser using the link pattern &lt;code&gt;&amp;lt;home server ip&amp;gt;:&amp;lt;casa os port&amp;gt;&lt;/code&gt;. You must setup an administrator account first and then login to view your dashboard. Your dashboard might have fewer apps than mine which now looks like this.&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.amazonaws.com%2Fuploads%2Farticles%2Fgbxutrz0b8uwlc9agv0i.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.amazonaws.com%2Fuploads%2Farticles%2Fgbxutrz0b8uwlc9agv0i.png" alt="Casa OS Dashboard" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have the following apps installed currently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Transmission:&lt;/strong&gt; A torrent client.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Immich:&lt;/strong&gt; Similar to Google Photos, backups my photos and videos.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AdGuard Home:&lt;/strong&gt; A personal DNS that I used to block unnecessary ads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jellyfin:&lt;/strong&gt; Similar to Netflix, but the media content are at your control 😉.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vaultwarden:&lt;/strong&gt; A password manager.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open WebUI:&lt;/strong&gt; I use it for user interface of my running &lt;a href="https://ollama.com/" rel="noopener noreferrer"&gt;Ollama&lt;/a&gt; models.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As of the moment, the following applications will suffice for my personal use case. Having this kind of machine helps me become more in control of my data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here comes the challenge...
&lt;/h2&gt;

&lt;p&gt;Even though my setup runs smoothly and within expectations, I still cannot access it outside my home network. Yeah, I touch some grass also 🤣. I need to access my home server outside of my home network but without the risk of exposing my data into public web.&lt;/p&gt;

&lt;p&gt;Here then comes VPN (Virtual Private Network) which is basically establishes a protected network connection when using public networks. I already have relevant experiences with this one as some of my previous projects involves private repositories that can only be accessed by connecting into the client's VPN. There are many solutions for this specific use case like &lt;a href="https://www.wireguard.com/" rel="noopener noreferrer"&gt;WireGuard&lt;/a&gt;, but in this particular blog, I chose &lt;a href="https://tailscale.com/" rel="noopener noreferrer"&gt;Tailscale&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Tailscale has a very generous free tier, which contains the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Up to 3 users&lt;/li&gt;
&lt;li&gt;Up to 100 devices&lt;/li&gt;
&lt;li&gt;Access to nearly all Tailscale features&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can start your Tailscale account &lt;a href="https://login.tailscale.com/start" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to use Tailscale in your home server. You need to install it first by running the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://tailscale.com/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing Tailscale, your device must be visible now in your Tailscale &lt;a href="https://login.tailscale.com/admin/machines" rel="noopener noreferrer"&gt;machine dashboard.&lt;/a&gt; They also have comprehensive &lt;a href="https://tailscale.com/kb" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; for other functionalities and guides.&lt;/p&gt;

&lt;p&gt;I installed their mobile application in my device, activated the VPN and I was able to view the IP designated to my home server.&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.amazonaws.com%2Fuploads%2Farticles%2Foljdg7omcg39ali9yjxj.jpg" 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.amazonaws.com%2Fuploads%2Farticles%2Foljdg7omcg39ali9yjxj.jpg" alt="My Tailscale Machines" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  But Michael, I don't want to input IP address when accessing my home server every time!
&lt;/h2&gt;

&lt;p&gt;I gotchu fam! Here's where DNS (Domain Name System) comes into action. DNS acts like a &lt;em&gt;phonebook&lt;/em&gt; of the internet which translates human readable domain names like &lt;em&gt;facebook.com&lt;/em&gt; into their appropriate IP addresses like the ones Tailscale VPN assigned to our corresponding machines.&lt;/p&gt;

&lt;p&gt;You can always buy some domain names online like in &lt;a href="https://domains.google/" rel="noopener noreferrer"&gt;Google Domains&lt;/a&gt;, &lt;a href="https://www.namecheap.com/" rel="noopener noreferrer"&gt;Namecheap&lt;/a&gt; and &lt;a href="https://www.godaddy.com/" rel="noopener noreferrer"&gt;GoDaddy&lt;/a&gt;. In this particular scenario, I will be using &lt;a href="https://www.duckdns.org/" rel="noopener noreferrer"&gt;Duck DNS&lt;/a&gt; which is a free dynamic public DNS.&lt;/p&gt;

&lt;p&gt;First, you must obtain your API key from Duck DNS by signing in. In my case, I use X to sign in and get my own API key. Then, register a subdomain you want to have and add the corresponding IP designated by Tailscale for your home server. Finally, your Duck DNS dashboard should look like this:&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.amazonaws.com%2Fuploads%2Farticles%2Fmgltxz8ih9qeoeeei7f0.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.amazonaws.com%2Fuploads%2Farticles%2Fmgltxz8ih9qeoeeei7f0.png" alt="Duck DNS dashboard" width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This single record will suffice as we will be using a reverse proxy to map each of our application. For the reverse proxy solution, we will be using &lt;a href="https://caddyserver.com/" rel="noopener noreferrer"&gt;Caddy&lt;/a&gt;, particularly &lt;strong&gt;xcaddy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To install xcaddy, log into your home server and run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; debian-keyring debian-archive-keyring apt-transport-https
curl &lt;span class="nt"&gt;-1sLf&lt;/span&gt; &lt;span class="s1"&gt;'https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key'&lt;/span&gt; | &lt;span class="nb"&gt;sudo &lt;/span&gt;gpg &lt;span class="nt"&gt;--dearmor&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; /usr/share/keyrings/caddy-xcaddy-archive-keyring.gpg
curl &lt;span class="nt"&gt;-1sLf&lt;/span&gt; &lt;span class="s1"&gt;'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt'&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/caddy-xcaddy.list
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;xcaddy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing xcaddy, run the following command to install Caddy with Duck DNS module included:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xcaddy build &lt;span class="nt"&gt;--with&lt;/span&gt; github.com/caddy-dns/duckdns
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The executable caddy file will be added in your current working directory and for the next steps, we will be setting up Caddy to run as a service. This Caddy &lt;a href="https://caddyserver.com/docs/running#manual-installation" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; will help you to make it happen.&lt;/p&gt;

&lt;p&gt;After setting the Caddy as a service, it's time for editing the Caddyfile. This file will hold your domain name/s to home server application/s mapping. Here's my configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# This configuration holds your API key configuration and enables you to use wildcard (*) for your Duck DNS domain
(duckdns) {
    tls {
        dns duckdns &amp;lt;YOUR API KEY HERE&amp;gt; {
            override_domain &amp;lt;YOUR SUBDOMAIN HERE&amp;gt;.duckdns.org
        }
    }
}

# This will be the root mapping of your Duck DNS domain to Casa OS dashboard
&amp;lt;YOUR SUBDOMAIN HERE&amp;gt;.duckdns.org {
    import duckdns
    reverse_proxy localhost:&amp;lt;YOUR CASA OS PORT&amp;gt;
}

# This will map wildcard domains to your home server applications. For this example, I use jellyfin
*.&amp;lt;YOUR SUBDOMAIN HERE&amp;gt;.duckdns.org {
    import duckdns

    @jellyfin host jellyfin.&amp;lt;YOUR SUBDOMAIN HERE&amp;gt;.duckdns.org
    handle @jellyfin {
        reverse_proxy localhost:&amp;lt;YOUR JELLYFIN PORT HERE&amp;gt;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, save the Caddyfile and restart the service using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart caddy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You must now be able to access your home server dashboard everywhere using Tailscale VPN and your Duck DNS name from your preferred web browser.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Just in case you're curious about the background image of my Casa OS dashboard, that was made by &lt;a href="https://ko-fi.com/artbymerisu" rel="noopener noreferrer"&gt;@artbymerisu&lt;/a&gt;. She's a great artist and creates beautiful anime wallpapers.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>docker</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Deploying FastAPI Application to AWS Fargate using Serverless Container Framework</title>
      <dc:creator>Michael Villaverde</dc:creator>
      <pubDate>Sat, 29 Mar 2025 12:21:36 +0000</pubDate>
      <link>https://dev.to/mbvillaverde/deploying-fastapi-application-to-aws-fargate-using-serverless-container-framework-5be0</link>
      <guid>https://dev.to/mbvillaverde/deploying-fastapi-application-to-aws-fargate-using-serverless-container-framework-5be0</guid>
      <description>&lt;p&gt;In this post, I will demonstrate how to deploy a FastAPI application to AWS Fargate using the Serverless Container Framework (SCF).&lt;/p&gt;

&lt;h1&gt;
  
  
  So, what's the Serverless Container Framework (SCF)?
&lt;/h1&gt;

&lt;p&gt;As stated in their documentation, the &lt;a href="https://www.serverless.com/containers/docs" rel="noopener noreferrer"&gt;Serverless Container Framework&lt;/a&gt; provides a unified development and deployment experience for containers on serverless platforms. Think of it the same as their Serverless Framework, but built for containers.&lt;/p&gt;

&lt;h1&gt;
  
  
  And what about FastAPI?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://fastapi.tiangolo.com/" rel="noopener noreferrer"&gt;FastAPI&lt;/a&gt; is a fast and modern web framework written in Python. It's often deployed in containers. You could also use Mangum, but we'll cover that another time. For now, we're using SCF to deploy our FastAPI application.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;I'll assume you already have an existing AWS account and a Serverless account, as these are necessary to successfully deploy our application. If you don't have them yet, use the following links to create them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/resources/create-account/" rel="noopener noreferrer"&gt;Creating an AWS Account&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.serverless.com/?view=register" rel="noopener noreferrer"&gt;Creating a Serverless Account&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Done creating your account? That's great! Now, I have a confession to make: my setup is tailored for those using VS Code or Cursor as their IDE. If you prefer other IDEs like PyCharm or NeoVIM, your setup might differ.&lt;/p&gt;

&lt;p&gt;So, let's proceed shall we? We'll need to install &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers" rel="noopener noreferrer"&gt;Dev Containers&lt;/a&gt; within VS Code or Cursor. After installation, we can clone the repository from &lt;a href="https://github.com/mbvillaverde/scf-fastapi-example" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's start the journey...
&lt;/h1&gt;

&lt;p&gt;After cloning the repository, open the project in your IDE. Ensure that the settings of &lt;strong&gt;"terminal.integrated.inheritEnv"&lt;/strong&gt; is set to &lt;code&gt;true&lt;/code&gt; and make the following environment variables exported in your integrated terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;your access key here&amp;gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;your secret key here&amp;gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;region you want to deploy the application&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After exporting the necessary variables, press &lt;strong&gt;Ctrl + Shift + P&lt;/strong&gt; (for Windows users) or &lt;strong&gt;Cmd + Shift + P&lt;/strong&gt; (for Mac users). This will open the Command Palette. Then, search for &lt;em&gt;"Dev Containers: Reopen in Container"&lt;/em&gt;. This will set up the project within a containerized environment, complete with &lt;strong&gt;AWS CLI&lt;/strong&gt;, &lt;strong&gt;Serverless Framework&lt;/strong&gt;, and &lt;strong&gt;Docker&lt;/strong&gt; installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;

&lt;p&gt;Here's what the project looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scf-fastapi-example/
├── .devcontainer/
│   └── devcontainer.json
├── app/
│   ├── Dockerfile
│   ├── main.py
│   ├── requirements.txt
│   └── static/
└── serverless.containers.yml        # Contains deployment config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside &lt;strong&gt;app/main.py&lt;/strong&gt; you'll find a simple FastAPI application. The &lt;strong&gt;app/Dockerfile&lt;/strong&gt; holds the instructions for building our FastAPI app into a reusable image. By default, SCF looks for the Dockerfile in the root folder of the service you're deploying.&lt;/p&gt;

&lt;p&gt;Let's take a look inside the &lt;code&gt;Dockerfile&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM python:3.12-slim-bullseye

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt

COPY . .

CMD ["fastapi", "run", "main.py", "--port", "8080"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're running FastAPI on port &lt;strong&gt;8080&lt;/strong&gt; by default because the local emulation of the Application Load Balancer within SCF points to port 8080.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;serverless.containers.yml&lt;/strong&gt; file contains the development and deployment configuration for SCF.&lt;/p&gt;

&lt;p&gt;Here's what the &lt;code&gt;serverless.containers.yml&lt;/code&gt; file looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;fastapi-example&lt;/span&gt;

&lt;span class="na"&gt;deployment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;awsApi@1.0&lt;/span&gt;

&lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./app&lt;/span&gt;
    &lt;span class="na"&gt;routing&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;pathPattern&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/*&lt;/span&gt;
      &lt;span class="na"&gt;pathHealthCheck&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/health&lt;/span&gt;
    &lt;span class="na"&gt;compute&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;awsFargateEcs&lt;/span&gt;
      &lt;span class="na"&gt;awsFargateEcs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;256&lt;/span&gt;
        &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;512&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;name&lt;/strong&gt; attribute defines the namespace for your services when deployed to AWS.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;deployment.type&lt;/strong&gt; specifies &lt;code&gt;awsApi&lt;/code&gt;, which deploys an AWS Application Load Balancer, networking components, and containers.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;containers.&lt;/strong&gt; will hold the configuration for each service deployed to AWS. For more detailed explanation of each attributes, refer to &lt;a href="https://www.serverless.com/containers/docs/configuration" rel="noopener noreferrer"&gt;this documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Running the Application Locally
&lt;/h1&gt;

&lt;p&gt;To run the project, open the integrated terminal and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;serverless login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose &lt;strong&gt;login/register&lt;/strong&gt; and you might encounter similar to this image below:&lt;br&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.amazonaws.com%2Fuploads%2Farticles%2Fkt0i6fs1ehwta6a7mlap.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.amazonaws.com%2Fuploads%2Farticles%2Fkt0i6fs1ehwta6a7mlap.png" alt="Image description" width="800" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the link and make sure that you are logged in to your Serverless account.&lt;/p&gt;

&lt;p&gt;Execute the following command to run the project locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;serverless dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After executing the above command, you will now see similar output like this one:&lt;br&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.amazonaws.com%2Fuploads%2Farticles%2Frlu8mgp3tti2fm0scllu.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.amazonaws.com%2Fuploads%2Farticles%2Frlu8mgp3tti2fm0scllu.png" alt="Image description" width="800" height="710"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can access your application in &lt;code&gt;http://localhost:3000/&lt;/code&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  Deploying the Application
&lt;/h1&gt;

&lt;p&gt;To deploy the project, run the following command in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;serverless deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deployment of the application might take some time. After executing the command and SCF performing the deployment processes. The output on your terminal must look like this one:&lt;br&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.amazonaws.com%2Fuploads%2Farticles%2Fps3pey146hi1rwe87712.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.amazonaws.com%2Fuploads%2Farticles%2Fps3pey146hi1rwe87712.png" alt="Image description" width="800" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To remove all the deployed components, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;serverless remove &lt;span class="nt"&gt;--force&lt;/span&gt; &lt;span class="nt"&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Serverless Container Framework (SCF) offers a streamlined approach to deploying services to AWS, particularly for containerized applications like FastAPI or Django. It simplifies the process by abstracting away much of the underlying infrastructure management, making it easier for developers to get their applications running in the cloud. With SCF, you can focus on building your application and let the framework handle the deployment complexities.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>python</category>
      <category>fastapi</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
