Deploying A Fastapi App With Kamal Aws Ecr And Github Actions

Leo Migdal
-
deploying a fastapi app with kamal aws ecr and github actions

These days I use Kamal to deploy my FastAPI (or Django) projects. Kamal is a simpler alternative to Kubernetes that you can use to deploy containerized apps to a VPS. Once you get the hang of it, it’ll only take you a few minutes to set up a CI/CD pipeline that automatically deploys your app to production with each push to the main branch. In this tutorial, I’ll walk you through the process of deploying a FastAPI app with Kamal, AWS ECR, and Github Actions. You can find the code for this tutorial in this repository. To make the most of this tutorial, you should:

I recently built a complete cloud deployment workflow for a FastAPI application using AWS and a modern DevOps toolchain. This setup takes a simple Python API and turns it into a fully automated, production-style deployment pipeline that runs reliably every time code is pushed to GitHub. The workflow starts by packaging the FastAPI application into a Docker image. Docker ensures the application behaves exactly the same in development, in CI pipelines and on the AWS EC2 instance. Once the image is built, it is pushed to Amazon ECR, which acts as a private, secure container registry designed specifically for storing and managing Docker images inside AWS. For infrastructure, I used Terraform instead of manually creating resources in the AWS console.

Terraform provisions everything: the EC2 instance that runs the application, the security group for inbound traffic, the IAM roles needed for the instance to pull images from ECR and the backend infrastructure used by... One of the most important components of this setup is the Terraform backend. Terraform stores its state in an S3 bucket, which acts as the central source of truth for the entire environment. A DynamoDB table complements this storage by providing state locking, ensuring that no two deployments ever modify the infrastructure at the same time. This combination of S3 for state management and DynamoDB for locking is the same approach used in real production systems. Deployment is fully automated with GitHub Actions.

Whenever I push code to the main branch, GitHub Actions builds the Docker image, logs into ECR, uploads the image and triggers Terraform to apply the latest configuration. The EC2 instance has a user-data script that installs Docker, authenticates to ECR automatically and pulls the newest version of the image. This means the application updates itself without any manual steps, SSH access or server configuration. All configuration, including the Dockerfile, Terraform scripts and CI/CD pipeline, is available in my GitHub repository. The structure includes a dedicated Terraform folder for infrastructure provisioning and a GitHub Actions workflow that manages the entire deployment from start to finish. This setup demonstrates a practical, scalable and repeatable approach to deploying Python microservices on AWS using nothing more than open-source tools and AWS-native services.

Tired of manually deploying your applications? What if you could push code to GitHub, run tests automatically, and deploy updates to your live server—without lifting a finger? That’s exactly what I did with my FastAPI project using CI/CD. I’ll walk you through how I set up a Continuous Integration (CI) pipeline to automatically test my code... Continuous Deployment (CD) pipeline to push updates to an AWS EC2 instance. Every other night, my wife wakes me up to tell me I’m muttering unintelligible phrases in my sleep: “restart nginx,” “the SSL certificate failed to validate,” or “how do I exit vim?”

I still suffer from PTSD from the days of manually deploying web apps. But since switching to Kamal, I’ve been sleeping like a baby1. Kamal is sort of a lightweight version of Kubernetes that you can use to deploy containerized apps to a VPS. It has a bit of a learning curve, but once you get the hang of it, it’ll take you less than 5 minutes to get an app in production with a CI/CD pipeline. A single push to main, and that green GitHub Actions checkmark confirms that your 2-pixel padding change is live for the world to admire. In this tutorial, I’ll walk you through the process of deploying a Django app with Kamal, AWS ECR, and Github Actions.

End‑to‑end CI/CD example that builds and tests a small FastAPI app, then builds & pushes a container image to AWS ECR using GitHub Actions. Optionally, it can run Pulumi (Python) to deploy the image to ECS Fargate (kept as an example in infra/). By default the pipeline does not push latest to avoid accidental overwrites. You can enable it via a workflow input/variable. Set these in Repo → Settings → Secrets and variables → Actions: Repository variables (Variables → New variable):

The workflow automatically creates the ECR repository if it doesn't exist. This project implements a REST API using FastAPI to expose a Machine Learning model. It is designed to be packaged with Docker, pushed to AWS ECR, and deployed to Kubernetes (EKS) using an automated GitHub Actions CI/CD workflow.

People Also Search

These Days I Use Kamal To Deploy My FastAPI (or

These days I use Kamal to deploy my FastAPI (or Django) projects. Kamal is a simpler alternative to Kubernetes that you can use to deploy containerized apps to a VPS. Once you get the hang of it, it’ll only take you a few minutes to set up a CI/CD pipeline that automatically deploys your app to production with each push to the main branch. In this tutorial, I’ll walk you through the process of dep...

I Recently Built A Complete Cloud Deployment Workflow For A

I recently built a complete cloud deployment workflow for a FastAPI application using AWS and a modern DevOps toolchain. This setup takes a simple Python API and turns it into a fully automated, production-style deployment pipeline that runs reliably every time code is pushed to GitHub. The workflow starts by packaging the FastAPI application into a Docker image. Docker ensures the application beh...

Terraform Provisions Everything: The EC2 Instance That Runs The Application,

Terraform provisions everything: the EC2 instance that runs the application, the security group for inbound traffic, the IAM roles needed for the instance to pull images from ECR and the backend infrastructure used by... One of the most important components of this setup is the Terraform backend. Terraform stores its state in an S3 bucket, which acts as the central source of truth for the entire e...

Whenever I Push Code To The Main Branch, GitHub Actions

Whenever I push code to the main branch, GitHub Actions builds the Docker image, logs into ECR, uploads the image and triggers Terraform to apply the latest configuration. The EC2 instance has a user-data script that installs Docker, authenticates to ECR automatically and pulls the newest version of the image. This means the application updates itself without any manual steps, SSH access or server...

Tired Of Manually Deploying Your Applications? What If You Could

Tired of manually deploying your applications? What if you could push code to GitHub, run tests automatically, and deploy updates to your live server—without lifting a finger? That’s exactly what I did with my FastAPI project using CI/CD. I’ll walk you through how I set up a Continuous Integration (CI) pipeline to automatically test my code... Continuous Deployment (CD) pipeline to push updates to...