Deploying Fastapi Microservices On Aws Eks With Terraform
Modern cloud applications need scalability, observability, and automation. Manually deploying infrastructure is outdated; instead, we use Infrastructure as Code (IaC) for reproducibility and monitoring tools to keep track of application health. In this blog, we’ll build and deploy a FastAPI microservice on Amazon EKS (Elastic Kubernetes Service) using Terraform, while integrating Datadog APM (Application Performance Monitoring) for real-time tracing and insights. Terraform provisions an EKS cluster and networking infrastructure. The FastAPI application is containerized with Docker and deployed to EKS. Datadog APM is integrated to collect real-time traces and metrics.
Observability is improved with Datadog dashboards, metrics, and alerts. Building the Infrastructure with Terraform 1️⃣ Provisioning the VPC The VPC module creates the necessary networking resources 2️⃣ Deploying the EKS Cluster We use the EKS module to create a Kubernetes cluster: This repository contains all necessary configurations and guidelines for deploying a bookstore application built with FastAPI on AWS Elastic Kubernetes Service (EKS) using Terraform. This project demonstrates setting up a robust Kubernetes cluster and deploying microservices that manage books and client data, utilizing an API Gateway for seamless service interaction. Before you start, make sure you have installed and configured the following tools:
Terraform Initialization and Application: This lab shows you how to deploy the microservices of the python-fastapi-demo-docker project onto your Amazon EKS cluster—either your AWS Fargate or managed node groups-based cluster. To gain a deeper understanding of the Kubernetes resources in these manifests, refer to Deploying FastAPI and PostgreSQL Kubernetes resources to Amazon EKS. Navigate to the root directory of the python-fastapi-demo-docker project where your environment variables are sourced: Run the following command from the python-fastapi-demo-docker project directory to create the ConfigMap: The expected output should look like this:
To confirm that your Kubernetes Configmap has been successfully created, you can use the kubectl get configmap command. This command lists all ConfigMaps that exist in the specified namespace: I've previously detailed deploying microservices on Azure AKS. In this guide, I expand on those insights, sharing my learnings on deploying FastAPI microservices on AWS EKS using Terraform to help others navigate the process smoothly. In this project, I configured an AWS Kubernetes cluster with two nodes using a "t2.small" instance type via Terraform in the region us-west-2 (Oregon). This setup hosts a simple bookstore application developed with a microservices architecture.
Key features include distinct services for managing books and client data, coordinated by Kubernetes. The system uses an API Gateway to facilitate service access and customize responses, including personalized messages and book discount information. efs_mount_targets.tf , eks_cluster.tf , eks_node_group.tf , iam_role.tf , internetgw.tf , provider.tf , rout.tf , sg.tf , subnet.tf , vpc.tf , efs-csi-driver-trust-policy.json As you can see, there is quite more complexity regarding configurations to deploy a simple K8s cluster into aws than into azure. Mainly configuring role permissions, access policies and network security. Set at least the following permission policies:
AWS's Elastic Kubernetes Service (EKS) is a managed service that lets you deploy, manage, and scale containerized applications on Kubernetes. In this tutorial, you will deploy an EKS cluster using Terraform. Then, you will configure kubectl using Terraform output and verify that your cluster is ready to use. AWS EKS clusters cost $0.10 per hour, so you may incur charges by running this tutorial. The cost should be a few dollars at most, but be sure to delete your infrastructure promptly to avoid additional charges. We are not responsible for any charges you may incur.
While you could use the built-in AWS provisioning processes (UI, CLI, CloudFormation) for EKS clusters, Terraform provides you with several benefits: Unified Workflow - If you already use Terraform to deploy AWS infrastructure, you can use the same workflow to deploy both EKS clusters and applications into those clusters. This project demonstrates microservices communication using FastAPI. It consists of three services that are built into Docker images and deployed to AWS EKS automatically. The infrastructure, including the EKS cluster and all required components, is provisioned using Terraform. Before deploying, update the following files:
After making these changes, push the modified code to your repository. GitHub Actions will automatically: Note: Homebrew is required for macOS. Modify the script if you are using Windows. This will configure your local environment and AWS credentials.
People Also Search
- Using IaC (Terraform) to Deploy a FastAPI Microservice on EKS with for ...
- Deploying FastAPI Microservices on AWS Elastic Kubernetes Service (EKS ...
- From Zero to Production: Deploying FastAPI Applications with Terraform ...
- Deploying FastAPI and PostgreSQL Microservices to EKS
- Deploying FastAPI Microservices on AWS EKS with Terraform:
- Provision an EKS cluster (AWS) - Terraform | HashiCorp Developer
- From Monolith to Microservices: My Journey Deploying FastAPI on AWS ...
- GitHub - andyg2025/fastApi_demo_EKS
Modern Cloud Applications Need Scalability, Observability, And Automation. Manually Deploying
Modern cloud applications need scalability, observability, and automation. Manually deploying infrastructure is outdated; instead, we use Infrastructure as Code (IaC) for reproducibility and monitoring tools to keep track of application health. In this blog, we’ll build and deploy a FastAPI microservice on Amazon EKS (Elastic Kubernetes Service) using Terraform, while integrating Datadog APM (Appl...
Observability Is Improved With Datadog Dashboards, Metrics, And Alerts. Building
Observability is improved with Datadog dashboards, metrics, and alerts. Building the Infrastructure with Terraform 1️⃣ Provisioning the VPC The VPC module creates the necessary networking resources 2️⃣ Deploying the EKS Cluster We use the EKS module to create a Kubernetes cluster: This repository contains all necessary configurations and guidelines for deploying a bookstore application built with ...
Terraform Initialization And Application: This Lab Shows You How To
Terraform Initialization and Application: This lab shows you how to deploy the microservices of the python-fastapi-demo-docker project onto your Amazon EKS cluster—either your AWS Fargate or managed node groups-based cluster. To gain a deeper understanding of the Kubernetes resources in these manifests, refer to Deploying FastAPI and PostgreSQL Kubernetes resources to Amazon EKS. Navigate to the r...
To Confirm That Your Kubernetes Configmap Has Been Successfully Created,
To confirm that your Kubernetes Configmap has been successfully created, you can use the kubectl get configmap command. This command lists all ConfigMaps that exist in the specified namespace: I've previously detailed deploying microservices on Azure AKS. In this guide, I expand on those insights, sharing my learnings on deploying FastAPI microservices on AWS EKS using Terraform to help others nav...
Key Features Include Distinct Services For Managing Books And Client
Key features include distinct services for managing books and client data, coordinated by Kubernetes. The system uses an API Gateway to facilitate service access and customize responses, including personalized messages and book discount information. efs_mount_targets.tf , eks_cluster.tf , eks_node_group.tf , iam_role.tf , internetgw.tf , provider.tf , rout.tf , sg.tf , subnet.tf , vpc.tf , efs-csi...