Skip to content

testdrivenio/fastapi-elastic-beanstalk

Repository files navigation

Deploying a FastAPI Application to Elastic Beanstalk

Check out the tutorial.

Want to use this project?

Local setup

  1. Fork/Clone

  2. Create and activate a virtual environment:

    $ python3 -m venv venv && source venv/bin/activate
  3. Install the requirements:

    (venv)$ pip install -r requirements.txt
  4. Spin-up a PostgreSQL container:

    (venv)$ docker run --name fastapi-songs-postgres -p 5432:5432 \
    -e POSTGRES_USER=fastapi-songs -e POSTGRES_PASSWORD=complexpassword123 \
    -e POSTGRES_DB=fastapi-songs -d postgres
  5. Initialize the database:

    (venv)$ python init_db.py
  6. Run the server:

    (venv)$ uvicorn main:app --reload
  7. Navigate to http://localhost:8000/ in your favorite web browser.

Elastic Beanstalk setup

  1. Install EB CLI.

  2. Initialize Elastic Beanstalk:

    $ eb init
  3. Create an Elastic Beanstalk environment:

    $ eb create fastapi-songs-env
  4. Configure AWS RDS and Certificate Manager

  5. Commit all the changed files to git and deploy:

    $ git add .
    $ git commit -m "updates for eb"
    
    $ eb deploy
  6. Open the web application in your favorite web browser:

    $ eb open