Tutorials
How to Build a Full-Stack Next.js App with AWS Amplify Gen 3
AWS Amplify Gen 3 combines hosting, managed PostgreSQL, authentication, and a Data API. Build a Next.js notes application locally, secure its data with SQL policies, and deploy it to AWS.
A small application often begins with a frontend, a few components, and some temporary data. Then users need accounts. The data needs to survive a page refresh, and eventually the application needs a database that can be accessed outside the developer’s computer.
At that point, even a relatively simple project may depend on several external services.
On November 30, 2026, AWS introduced a new generation of Amplify that brings these responsibilities into a single platform.
AWS Amplify Gen 3 provides application hosting, managed PostgreSQL, authentication based on Better Auth, and an automatically generated PostgREST-compatible Data API.
For developers familiar with Supabase, parts of this architecture will look familiar. The database is relational, access policies are written in SQL, and frontend applications can communicate with the backend through a client library.
In this tutorial, we will build a small Next.js application where users can create, read, and delete their own notes.
The application will run locally before being deployed to AWS.
How Amplify Gen 3 works
The architecture differs considerably from previous generations of Amplify.
Instead of defining the entire backend through TypeScript infrastructure constructs, a simple project can use a configuration file and SQL migrations.
The application communicates with the managed backend through @aws-amplifygen3/backend-client-js.
Authentication establishes the user’s identity. The Data API then uses that identity when executing database operations.
flowchart TD
A["Next.js application"] --> B["Amplify Backend SDK"]
B --> C["Better Auth"]
B --> D["Data API"]
C -->|User session| B
D --> E["PostgreSQL 17"]
E --> F["Row-Level Security"]
F --> G["User's notes"]
Notice that authentication and data authorization are separate concerns.
Knowing that a user has signed in does not establish which records that user should be allowed to access.
That second decision belongs to PostgreSQL and its access policies.
1. Prepare the development environment
You will need:
- Node.js 22.12 or newer.
- npm 10 or newer.
- An updated AWS CLI v2.
- Docker or Finch for local backend development.
- An AWS account with appropriate permissions when deploying.
Check whether your AWS CLI already supports Amplify Gen 3:
aws amplifygen3 help
If the command is not recognized, update AWS CLI v2 using the official AWS installation instructions.
There is no need to configure AWS credentials yet if you only intend to develop locally.
Check that Docker is running:
docker info
Amplify uses containers to provide the local database, authentication service, and Data API.
2. Create the Next.js project
Create a TypeScript application using the App Router:
npx create-next-app@latest notes-app --ts --app --eslint --no-tailwind --no-src-dir --import-alias "@/*" --use-npm --yes
Open the project:
cd notes-app
Initialize Amplify with a backend:
aws amplifygen3 local init --type fullstack
The command prepares the project configuration, creates a migration directory, and installs the backend client dependencies.
Your project should now contain files resembling:
notes-app/
├── app/
├── migrations/
├── public/
├── amplify.jsonc
├── next.config.ts
├── package.json
└── tsconfig.json
The amplify.jsonc file describes the application and its deployment configuration.
The migrations/ directory will contain the SQL needed to construct and modify the database.
Neither the initialization command nor the creation of a migration provisions a cloud database.
One detail that may cause confusion when following older Amplify tutorials is the CLI itself.
Commands such as:
npx ampx sandbox
belong to Amplify Gen 2.
Gen 3 uses the aws amplifygen3 command group instead.
3. Create the PostgreSQL database schema
Our application needs somewhere to store notes.
Each note will contain an identifier, a title, some text, its owner’s identifier, and a creation timestamp.
Generate a migration file:
aws amplifygen3 local migration create --description "create notes table"
Open the newly created SQL file in migrations/ and add:
CREATE TABLE public.notes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
owner_id TEXT NOT NULL DEFAULT auth.uid(),
title TEXT NOT NULL CHECK (char_length(title) BETWEEN 1 AND 120),
body TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX notes_owner_idx
ON public.notes (owner_id);
The owner_id column deserves particular attention.
Its default value comes from auth.uid(), which returns the authenticated user’s identifier.
The frontend therefore does not need to supply an owner when creating a note.
But a default value alone is not a security mechanism.
What prevents a user from explicitly supplying somebody else’s identifier?
For that, we need Row-Level Security.
Add the following SQL to the same migration:
ALTER TABLE public.notes ENABLE ROW LEVEL SECURITY;
REVOKE ALL ON public.notes FROM anon;
GRANT SELECT, INSERT, DELETE
ON public.notes TO authenticated;
CREATE POLICY notes_read
ON public.notes
FOR SELECT
TO authenticated
USING (
owner_id = (SELECT auth.uid())
);
CREATE POLICY notes_create
ON public.notes
FOR INSERT
TO authenticated
WITH CHECK (
owner_id = (SELECT auth.uid())
);
CREATE POLICY notes_remove
ON public.notes
FOR DELETE
TO authenticated
USING (
owner_id = (SELECT auth.uid())
);
The grants establish which operations authenticated users may perform. The policies determine which rows those operations may access.
An authenticated user can read or delete a note only when its owner_id matches their identity.
The insertion policy also prevents them from creating a note assigned to another user.
We deliberately omit UPDATE permissions because this application does not implement editing.
This is preferable to granting permissions for operations the application does not yet need.
4. Configure the Amplify backend client
Amplify provides two environment variables:
AMPLIFY_BACKEND_URL
AMPLIFY_BACKEND_PUBLISHABLE_KEY
The first identifies the backend. The second allows the client application to access it under the configured permissions.
Both can be used in browser code.
Open next.config.ts and add the env configuration:
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
env: {
AMPLIFY_BACKEND_URL:
process.env.AMPLIFY_BACKEND_URL,
AMPLIFY_BACKEND_PUBLISHABLE_KEY:
process.env.AMPLIFY_BACKEND_PUBLISHABLE_KEY,
},
};
export default nextConfig;
Preserve any other Next.js configuration your project requires.
Amplify supplies the corresponding values when running locally or deploying the application.
There is no need to hardcode a production backend URL.
Also, do not confuse the publishable key with privileged AWS credentials. The publishable key is intended for frontend usage; administrator credentials are not.
The difference becomes particularly significant when a privileged database connection can bypass RLS entirely.
5. Start the local backend and generate TypeScript types
Start Docker or Finch if it is not already running.
From the project directory, execute:
aws amplifygen3 local run
Amplify starts the local services, applies pending SQL migrations, and launches the application’s development server.
The command also reports addresses for the local backend, management console, and Mailpit.
Mailpit captures authentication emails locally, which is useful when implementing account verification or password recovery.
Open a second terminal and generate TypeScript definitions from the database:
aws amplifygen3 local gen-types --output-file db.types.ts
The generated file describes the database tables, columns, and their corresponding TypeScript types.
Create lib/backend.ts:
import { createClient } from "@aws-amplifygen3/backend-client-js";
import type { Database } from "@/db.types";
type BackendClient = ReturnType<typeof createClient<Database>>;
let client: BackendClient | undefined;
export function backend() {
const url = process.env.AMPLIFY_BACKEND_URL;
const key = process.env.AMPLIFY_BACKEND_PUBLISHABLE_KEY;
if (!url || !key) {
throw new Error("Missing Amplify backend configuration");
}
client ??= createClient<Database>(url, key);
return client;
}
The client is initialized when first requested rather than immediately when the module is imported.
Passing Database to createClient() also gives TypeScript information about the available tables and query results.
For example, querying a nonexistent column can now be detected during development.
However, generated types do not describe the current user’s permissions. A query can be perfectly valid in TypeScript and still be rejected by PostgreSQL.
6. Build the authentication and notes page
Replace app/page.tsx with the following implementation.
This example intentionally keeps the interface simple. Its purpose is to demonstrate how authentication and database access work together.
"use client";
import { useEffect, useState } from "react";
import { backend } from "@/lib/backend";
import type { Tables } from "@/db.types";
type Note = Pick<
Tables<"notes">,
"id" | "title" | "body"
>;
export default function NotesPage() {
const [email, setEmail] = useState<string | null>(null);
const [notes, setNotes] = useState<Note[]>([]);
const [loading, setLoading] = useState(true);
const [message, setMessage] = useState("");
async function loadNotes() {
const { data, error } = await backend()
.from("notes")
.select("id, title, body")
.order("created_at", { ascending: false });
if (error) {
setMessage(error.message);
return;
}
setNotes(data ?? []);
}
useEffect(() => {
let active = true;
async function initialize() {
try {
const { data, error } =
await backend().auth.getSession();
if (!active) return;
if (error) {
setMessage(error.code ?? "Session check failed");
return;
}
const session = data?.session;
if (!session) return;
setEmail(session.user.email);
const result = await backend()
.from("notes")
.select("id, title, body")
.order("created_at", { ascending: false });
if (!active) return;
if (result.error) {
setMessage(result.error.message);
return;
}
setNotes(result.data ?? []);
} catch {
if (active) {
setMessage("Could not initialize the application");
}
} finally {
if (active) setLoading(false);
}
}
void initialize();
return () => {
active = false;
};
}, []);
async function authenticate(
form: FormData,
register: boolean
) {
setMessage("");
const credentials = {
email: String(form.get("email")),
password: String(form.get("password")),
};
try {
const auth = backend().auth;
const { error } = register
? await auth.signUp.email(credentials)
: await auth.signIn.email(credentials);
if (error) {
setMessage(error.code ?? "Authentication failed");
return;
}
const { data } = await auth.getSession();
if (data?.session) {
window.location.reload();
return;
}
setMessage(
"Account created. Sign in or complete email verification."
);
} catch {
setMessage("Could not complete authentication");
}
}
async function addNote(form: FormData) {
setMessage("");
const title = String(form.get("title")).trim();
const body = String(form.get("body")).trim();
if (!title || !body) {
setMessage("Enter a title and note");
return;
}
try {
const { error } = await backend()
.from("notes")
.insert({ title, body });
if (error) {
setMessage(error.message);
return;
}
await loadNotes();
} catch {
setMessage("Could not save the note");
}
}
async function deleteNote(id: string) {
setMessage("");
try {
const { error } = await backend()
.from("notes")
.delete()
.eq("id", id);
if (error) {
setMessage(error.message);
return;
}
await loadNotes();
} catch {
setMessage("Could not delete the note");
}
}
async function signOut() {
try {
const { error } = await backend().auth.signOut();
if (error) {
setMessage(error.code ?? "Sign-out failed");
return;
}
window.location.reload();
} catch {
setMessage("Could not sign out");
}
}
if (loading) {
return <p>Loading...</p>;
}
if (!email) {
return (
<main>
<h1>My Notes</h1>
<form action={(form) => authenticate(form, false)}>
<input
name="email"
type="email"
placeholder="Email"
required
/>
<input
name="password"
type="password"
placeholder="Password"
minLength={8}
required
/>
<button type="submit">Sign in</button>
<button
formAction={(form) => authenticate(form, true)}
>
Create account
</button>
</form>
<p role="status">{message}</p>
</main>
);
}
return (
<main>
<h1>My Notes</h1>
<p>Signed in as {email}</p>
<button onClick={signOut}>
Sign out
</button>
<form action={addNote}>
<input
name="title"
placeholder="Title"
maxLength={120}
required
/>
<textarea
name="body"
placeholder="Write a note"
required
/>
<button type="submit">Save note</button>
</form>
<p role="status">{message}</p>
{notes.map((note) => (
<article key={note.id}>
<h2>{note.title}</h2>
<p>{note.body}</p>
<button onClick={() => deleteNote(note.id)}>
Delete
</button>
</article>
))}
</main>
);
}
Email and password authentication is enabled by default in the backend configuration.
The page checks whether a session exists, loads the user’s notes, and provides basic operations for creating and deleting them.
There is no custom Next.js API route in this example.
The browser communicates directly with Amplify’s Data API through the backend client.
That is safe only because the database policies restrict what each authenticated user may access.
7. Test whether Row-Level Security actually works
Open the application at the address printed by local run, normally:
http://localhost:3000
Create an account and add a note.
Then sign out and register a different account.
The second account should not see the first account’s note.
But that checks only one part of the security model.
A useful test should also include attempts to insert a note with another user’s identifier and delete a record belonging to another account. Those operations must not modify the other user’s data.
| Operation | Expected behavior |
|---|---|
| Read your own notes | Allowed |
| Read another user’s notes | No matching rows returned |
| Create a note for yourself | Allowed |
| Create a note for another user | Rejected by RLS |
| Delete another user’s note | No matching rows deleted |
| Read notes without signing in | Permission denied |
The distinction between rejection and an empty result is important.
PostgreSQL may simply exclude rows that the current user is not permitted to access. A deletion request against an inaccessible record can therefore complete without an error while deleting nothing.
You can also inspect the database directly:
aws amplifygen3 local db query "SELECT id, owner_id, title FROM public.notes"
This command uses an administrative database account.
Consequently, it can return notes belonging to multiple users.
Do not mistake that behavior for an RLS failure.
The policies must be tested through the Data API using actual authenticated and unauthenticated sessions.
Amplify also provides a database linter:
aws amplifygen3 local db lint --level error
It can detect certain security configuration mistakes, although it cannot establish that every application-specific policy behaves correctly.
8. Deploy to AWS
Once the application works locally, configure your AWS credentials if necessary.
Check the active identity:
aws sts get-caller-identity
If you use AWS IAM Identity Center:
aws sso login
Make sure your active AWS Region supports Amplify Gen 3 and that the account has the required deployment permissions.
Deploy the application:
aws amplifygen3 deploy
The first deployment provisions the application and its backend.
Amplify performs the build remotely and applies the SQL migrations to the preview backend.
When deployment finishes, the CLI reports a preview URL.
Open it and create another account.
Your local users will not exist there.
That is intentional.
9. Understand preview and production databases
One of the more interesting aspects of Amplify Gen 3 is how it separates backend environments.
Local development uses the database running on your computer.
Preview deployments use their own backend branches, and production has a separate backend.
flowchart TD
A["Application source code"] --> B["Local development"]
A --> C["Preview deployment"]
A --> D["Production deployment"]
B --> E["Local PostgreSQL and users"]
C --> F["Preview PostgreSQL and users"]
D --> G["Production PostgreSQL and users"]
H["SQL migrations"] --> E
H --> F
H --> G
The environments share the application’s schema through migration files, not its stored records.
For example, creating a user locally does not create that user in production.
Similarly, deleting a note from a preview database does not delete the corresponding production data.
After reviewing the preview application, deploy to production:
aws amplifygen3 deploy --env production
Subsequent calls to deploy without the environment argument still target preview by default.
This makes it less likely that an ordinary development deployment will unintentionally replace the production application.
It does not, however, remove the need to review database migrations before applying them to production.
A destructive SQL migration remains destructive regardless of how convenient the deployment process is.
Working with database changes
Suppose you later decide that notes should have an optional category.
Rather than editing the original migration, create another one:
aws amplifygen3 local migration create --description "add note category"
Add:
ALTER TABLE public.notes
ADD COLUMN category TEXT;
Apply the migration locally:
aws amplifygen3 local migration apply
Regenerate your TypeScript definitions:
aws amplifygen3 local gen-types --output-file db.types.ts
Then check the application:
npx tsc --noEmit
Amplify records migration history and checks the contents of previously applied files.
Editing a migration that has already been applied can produce a checksum_mismatch error.
For ongoing development, treat applied migrations as historical records. Introduce schema changes through new files instead of rewriting the existing history.
Is AWS Amplify Gen 3 free?
AWS introduced three main pricing plans at launch.
| Plan | Monthly price |
|---|---|
| Basic | $0 |
| Pro | $20 |
| Pro Plus | $45 |
The Basic plan supports up to 25 applications and two backends, subject to resource allowances.
It also has limitations. For example, inactive backends can be paused after seven days, and point-in-time database restoration is unavailable on Basic.
Local development does not consume Amplify cloud resources.
Cloud deployment is different. Review the current pricing, storage allowances, and any separately billed AWS integrations before leaving resources running.
To stop the local environment:
aws amplifygen3 local stop
Local data is retained for subsequent development sessions.
If you no longer need the deployed tutorial application, you can delete it:
aws amplifygen3 app delete --app notes-app --yes
Be careful with the last command.
It permanently removes the selected application and its environments, including backend databases, users, and backups.
Is Amplify Gen 3 an alternative to Vercel and Supabase?
For certain applications, yes.
The architecture covers a similar set of requirements: framework hosting, relational data storage, authentication, and a frontend-accessible database API.
But the more interesting question concerns what happens when the project grows.
A small notes application needs little beyond a database and authentication. A larger application may require scheduled jobs, object storage, external integrations, custom authorization, or more control over database infrastructure.
Amplify Gen 3 can connect to other AWS services, while Supabase and Vercel have their own integration models.
Choosing between them involves more than comparing their initial setup commands.
What makes the new Amplify worth examining is the development workflow itself.
You can define the database in SQL, generate TypeScript types, test authentication and access policies locally, and deploy the frontend and backend together.
For developers already comfortable with Next.js and PostgreSQL, that removes several infrastructure decisions from the beginning of a project without removing the need to understand the database.
The latter remains important.
Our notes application does not protect user data because its interface hides another user’s records. It protects that data because PostgreSQL refuses to expose rows outside the authenticated user’s permissions.
That is a distinction worth preserving as the application becomes more complicated.
External Sources used for this article
- AWS — Reintroducing AWS Amplify, November 30, 2026
- AWS Amplify — Full-Stack Application Tutorial
- AWS Amplify — Backend Architecture
- AWS Amplify — Local Development
- AWS Amplify — API Keys and Roles
- AWS Amplify — Tables and Migrations
- AWS Amplify — Generate TypeScript Types
- AWS Amplify — Local Database
- AWS Amplify — Pricing and Spend Limits