Serverless PostgreSQL
Build at the speed of an idea with AWS Databases. Create a new database in seconds and add features on-demand as your application grows. Focus on coding, not infrastructure management—our serverless, fully managed PostgreSQL and NoSQL databases automatically scale with your workload while you only pay for what you use. Whether you're prototyping your next big idea or powering production AI and data-driven applications, AWS Databases deliver the security, reliability, and price performance you need without the operational overhead.
Get started for free with $100 in credits towards any of these databases.
This guide demonstrates how to build a simple Hello World Next.js web application. You can also alternatively use our sample template to get started with a Vercel project and Aurora PostreSQL database.
The application, hosted on Vercel, establishes secure database connections without hardcoded access credentials by leveraging Vercel's OIDC Federation and DSQL IAM authentication.
Connecting your project links the relevant environment variables. To use these variables in your local development environment, run:
vercel env pullIn this guide, we use the node-postgres but you use any next.js and postgreSQL compatible driver of your choice:
npm install pg @aws/aurora-dsql-node-postgres-connector @vercel/functionsNavigate to your DSQL Cluster in the AWS DSQL Console. Click Connect with Query Editor and then Connect. Use the Query Editor to create a single table for our example application by executing:
CREATE TABLE IF NOT EXISTS comments (comment TEXT);You can access the AWS DSQL Console from the Storage tab on your Vercel Dashboard, by selecting "Open in AWS".
Create the database handler functions:
import { AuroraDSQLPool } from "@aws/aurora-dsql-node-postgres-connector";import { awsCredentialsProvider } from "@vercel/oidc-aws-credentials-provider";import { ClientBase } from "pg";import { attachDatabasePool } from "@vercel/functions";
const pool = new AuroraDSQLPool({ host: process.env.PGHOST, region: process.env.AWS_REGION, user: process.env.PGUSER || "admin", database: process.env.PGDATABASE || "postgres", port: Number(process.env.PGPORT || 5432), customCredentialsProvider: awsCredentialsProvider({ roleArn: process.env.AWS_ROLE_ARN, clientConfig: { region: process.env.AWS_REGION }, }),});attachDatabasePool(pool);
// Single query transaction.export async function query(sql: string, args: unknown[]) { return pool.query(sql, args);}
// Use it for multiple queries transaction.export async function withConnection<T>( fn: (client: ClientBase) => Promise<T>,): Promise<T> { const client = await pool.connect(); try { return await fn(client); } finally { client.release(); }}You can update the page.tsx file in your starter project in the following manner to display the comment from the database.
import { query } from '@/lib/db';
export default async function Page() { const response = await query('select * from comments'); const comments = response.rows;
return ( <main className="main"> <h1 className="title">Next.js + Aurora PostgreSQL</h1>
<div className="container"> {comments.map(comment => ( <div> <p>{comment.comment}</p> <div className="metadata">{comment.id}</div> </div> ))} </div> </main> );}You're now ready to start your app locally:
npm run devNavigate to https://localhost:3000
Once ready, you can deploy your application to Vercel.
Select your preferred product and proceed to install. New to AWS? Create a new AWS account with $100 in credit - no credit card required (under free plan). Your credits remain available even after upgrading to a paid account later.
Under the free plan, new AWS customers get $100 in free credits to explore all eligible AWS services—valid for 6 months, no strings attached. As your needs grow, simply upgrade to a paid plan and scale beyond free tier limits. All billing is handled directly through AWS.