Add a Database
How to add a dedicated database to your Shuttle project.
Add a Dedicated Database
Add a managed, dedicated Postgres database to your Shuttle Cobra project. This allows your application to persist data, serving as a robust and scalable relational database solution without needing to manage the underlying infrastructure yourself. Shuttle automatically handles provisioning, scaling, and connection management.
Prerequisites
An existing Shuttle project (Python)
uvinstalled and a virtual environment activated for dependency managementAWS credentials configured locally (e.g., via
aws configure, environment variables likeAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, etc.)
Instructions: Provisioning a Dedicated Postgres Database
This guide will walk you through adding a dedicated Postgres database to your Shuttle Cobra application.
1. Install Dependencies
First, add the shuttle-db[postgres] package to your project using uv:
uv init
uv add shuttle-cobraThis will install the necessary shuttle-rds package and its Postgres-specific dependencies, including database drivers like psycopg.
2. Define Your Database in main.py
main.pyIn your project's main.py file, import RdsPostgres and RdsPostgresOptions from shuttle_aws.rds. Then, add the RdsPostgres resource as an argument to your @shuttle_task.cron (or other service) decorated function, using type annotations. You can customize the database using RdsPostgresOptions (e.g., instance size, storage, etc., though for a basic guide, default options are sufficient).
Last updated