View a markdown version of this page

Database - AWS Amplify

Database

Each Amplify backend includes a PostgreSQL database. You can connect your applications to the database with the Data API, or with PostgreSQL clients and tools such as psql, Drizzle, and Prisma. AWS Amplify creates the database with your backend and runs it, and each deployment applies the schema and access rules in your repository.

The database is serverless. You don’t choose instance sizes, and you don’t pay for compute while no one is using your app. The database wakes in seconds when users arrive, and scales to handle more of them as your app grows, with no migration to a larger database.

By default, each app has two environments, production and preview, and each environment has its own backend branch. Each environment that you add, and each Git branch that you push, also gets its own backend branch.

Backend branches are isolated from each other. Each backend branch has its own database, auth, schema, publishable key and backend URL. Test users that you create in preview can’t sign in to production. A new backend branch starts with your schema and no rows or users, and deployments never copy data between backend branches. To test with sample data, seed a backend branch with the Amplify CLI after a deployment. For more information, see Seed your database.

About the database

The database has the following characteristics:

  • Serverless – The database scales up and down with your app’s load, up to the maximum capacity that you set for each environment.

  • Sleeps when idle – When your app has no traffic, the backend goes to sleep, and the next request wakes it in seconds. You’re not charged for compute while it’s asleep. For more information about capacity and idle behavior, see Capacity.

  • Usage – Amplify counts storage whether or not your app has traffic. For more information about backend pricing, see Pricing and spend limits.

  • A backend branch for each Git branch – Each Git branch that you push gets its own backend branch. Merging the Git branch doesn’t delete it. To delete one, run aws amplifygen3 branch delete.

  • Point-in-time restore – Amplify keeps backups for the retention period that you set for each environment. You can restore production to any time in that window. Amplify restores the data into a new backend branch.

  • Extensions – You can turn on the PostgreSQL extensions that Amplify allows, such as pgvector and PostGIS.

  • Local development – To run the database on your computer, see Develop locally.

Work with the database

Use the following pages to work with the database:

  • Connect to your database – Run SQL, and connect psql, other PostgreSQL clients and server code with your AWS credentials.

  • Tables and migrations – Create and change tables with SQL migrations. Each deployment applies them to the environment’s backend branch.

  • Seed your database – Load sample data into a deployed environment from a seed file.

  • Secure your data – Grant access to your tables, and write row-level security (RLS) policies for the rows that each user can read and change.

  • Extensions – Turn on the PostgreSQL extensions that Amplify allows, such as pgvector and PostGIS.

  • PostgreSQL differences – See what differs from a PostgreSQL server that you run yourself.

  • Backups and restore – Set how long Amplify keeps backups, and restore production to a point in time.

  • Capacity – Set the maximum capacity for each environment, and see how the database scales.