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 <a href="https://github.com/pypa/pipx#install-pipx" rel="noopener ugc nofollow" target="_blank">pipx</a> to install the <strong>Elastic Beanstalk CLI</strong>. Follow the instructions <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html" rel="noopener ugc nofollow" target="_blank">here</a> to install AWS’s CLI if you do not already have that installed. Then configure it following <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 <code>poetry</code> to manage your dependencies, run the following commands in your terminal:</p>
<pre>
poetry new deployment-example
cd deployment-example
poetry add fastapi "uvicorn[standard]" 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 <code>tortoise-orm</code> as our ORM here, but feel free to use anything else (e.g., <code>sqlmodel</code>, <code>sqlalchemy</code>, etc…). <strong>Notice that we installed the standard version of </strong><code><strong>uvicorn</strong></code><strong> that will help us later on during deployment</strong>. Create a <em>main.py</em> file inside of <code>deployment_example</code> 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>