Full PostgreSQL compatibility
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 RDS IAM authentication.
Connecting your project links the relevant environment variables. To use these variables in your local development environment, run:
vercel env pullAurora Serverless is fully postgresql compatible. In this guide, we use the node-postgres but you can use any next.js and postgreSQL compatible driver of your choice.
npm install pg @aws-sdk/rds-signer @vercel/functionsIn AWS Console or using any compatible Postgres driver, create the database table by running the following SQL command:
CREATE TABLE IF NOT EXISTS comments ( id SERIAL PRIMARY KEY, comment TEXT)Create the database handler functions:
import { awsCredentialsProvider } from "@vercel/functions/oidc";import { attachDatabasePool } from "@vercel/functions";import { Signer } from "@aws-sdk/rds-signer";import { ClientBase, Pool } from "pg";
const signer = new Signer({ hostname: process.env.PGHOST, port: Number(process.env.PGPORT), username: process.env.PGUSER, region: process.env.AWS_REGION, credentials: awsCredentialsProvider({ roleArn: process.env.AWS_ROLE_ARN, clientConfig: { region: process.env.AWS_REGION }, }),});
const pool = new Pool({ host: process.env.PGHOST, user: process.env.PGUSER, database: process.env.PGDATABASE || "postgres", // The auth token value can be cached for up to 15 minutes (900 seconds) if desired. password: () => signer.getAuthToken(), port: Number(process.env.PGPORT), // Recommended to switch to `true` in production. // See https://docs.aws.amazon.com/lambda/latest/dg/services-rds.html#rds-lambda-certificates ssl: { rejectUnauthorized: false }, max: 20,});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.