Menu

1 / 2

How to deploy Fast API

DEV Community·Lia·6 months ago
#vKJCALex
#fastapi#aws#docker#software#fullscreen
Reading 0:00
15s threshold

FastAPI + Docker + AWS EC2 Deployment Guide

Prerequisites (Local)

1. Create a Dockerfile

Create a Dockerfile in your project root:

FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

Enter fullscreen mode

Exit fullscreen mode

If your project structure follows app/main.py , set the entry point as app.main:app

2. Push to GitHub

git add Dockerfile git commit -m "Add Dockerfile" git push origin main

Enter fullscreen mode

Exit fullscreen mode

AWS EC2 Setup

⚠️ We were using a provided AWS account, so the EC2 setup process is slightly different from the standard approach. Follow the steps below carefully.

3. Create a Security Group First

EC2 Console → Left menu Security Groups → Create security group

Enter name and description

Select VPC → Click Create

Wait 5–10 seconds (for automatic tag attachment)

4.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.