FastAPI on AWS with MongoDB Atlas and Okta

Rajan Khullar
2 min readJun 16, 2023

Objective

After going through this tutorial series you’ll have a better understanding of how to create backend python endpoints that read and write to MongoDB Atlas and are secured behind Okta.

Background

FastAPI is a modern high-performance web framework for building backend API endpoints with Python. The usage of type hints and pydantic for request validation makes the code much cleaner than writing custom validation logic. And it allows the framework to generate OpenAPI docs, which makes the endpoints easy for engineers to manually test and integrate against.

Architecture

We’ll be deploying the backend endpoints to AWS API Gateway and Lambda, which gives us a common type of serverless architecture that’s relatively easy to get started with and should have little to no cost at 20 api requests per minute. There are two main types of endpoints under API Gateway, REST and HTTP. We’ll be using HTTP since it features built in support for JWT authorization. That’s key to protect the lambda function from being invoked by bots or bad actors. Part 3 of the tutorial walks through the deployment details after you’re able to develop and test out the endpoints locally.

Codebase

You can browse the code used throughout this tutorial more in depth on GitHub: https://github.com/rkhullar/example-webapp

Tutorial

--

--