Deploy FastAPI to AWS Elastic Beanstalk (Zero to Hero)

<p>This guide will go over how to deploy a FastAPI app, add a `postgres` database, and attach a SSL certificate (assuming you have purchased a custom domain).</p> <h2>Prerequisites</h2> <p>This tutorial will be using&nbsp;<a href="https://github.com/pypa/pipx#install-pipx" rel="noopener ugc nofollow" target="_blank">pipx</a>&nbsp;to install the&nbsp;<strong>Elastic Beanstalk CLI</strong>. Follow the instructions&nbsp;<a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html" rel="noopener ugc nofollow" target="_blank">here</a>&nbsp;to install AWS&rsquo;s CLI if you do not already have that installed. Then configure it following&nbsp;<a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html" rel="noopener ugc nofollow" target="_blank">this guide</a>.</p> <h2>FastAPI Project</h2> <p>Assuming that you are using&nbsp;<code>poetry</code>&nbsp;to manage your dependencies, run the following commands in your terminal:</p> <pre> poetry new deployment-example cd deployment-example poetry add fastapi &quot;uvicorn[standard]&quot; tortoise-orm pydantic</pre> <p>Our folder structure will look something like this:</p> <pre> . ├── README.rst ├── deployment_example │ └── __init__.py ├── poetry.lock ├── pyproject.toml └── tests ├── __init__.py └── test_deployment_example.py</pre> <p>Note that we are using&nbsp;<code>tortoise-orm</code>&nbsp;as our ORM here, but feel free to use anything else (e.g.,&nbsp;<code>sqlmodel</code>,&nbsp;<code>sqlalchemy</code>, etc&hellip;).&nbsp;<strong>Notice that we installed the standard version of&nbsp;</strong><code><strong>uvicorn</strong></code><strong>&nbsp;that will help us later on during deployment</strong>. Create a&nbsp;<em>main.py</em>&nbsp;file inside of&nbsp;<code>deployment_example</code>&nbsp;to start coding our API:</p> <p><a href="https://medium.com/@malthunayan4/deploy-fastapi-to-aws-elastic-beanstalk-zero-to-hero-1c9bec4fbc97"><strong>Learn More</strong></a></p>
Tags: FastAPI AWS