Building a full-stack application involves more than writing frontend components. A production application also needs authentication, a database, APIs, authorization, hosting, environment configuration, and a reliable deployment process.
Traditionally, developers configure these services separately. They create a database, build backend APIs, configure authentication, connect the frontend, and establish a deployment pipeline. Each component requires its own configuration and maintenance.
AWS Amplify simplifies this process by bringing application hosting and backend capabilities into a managed development workflow. Developers can define backend resources, connect them to a frontend, test changes locally, and deploy the application to AWS.
The latest AWS Amplify experience introduces a code-first approach for defining application backends. Developers can describe database tables, authentication settings, and data access rules using files in their project. Amplify provisions the backend and connects it to the application during deployment.
In this article, we will build a full-stack notes application using Next.js and AWS Amplify. We will configure authentication, create a PostgreSQL database, implement user-specific data access, run the application locally, and deploy preview and production environments.
1. What Is AWS Amplify?
AWS Amplify is a collection of managed services and developer tools for building, deploying, and hosting web and mobile applications.
It provides capabilities for frontend hosting, backend development, authentication, database access, and application deployment.
Instead of manually connecting every AWS service, developers can use Amplify to manage common application requirements through a unified workflow.
The latest Amplify backend experience provides:
Managed PostgreSQL database.
User registration and authentication.
Database-generated data APIs.
Row-level security for controlling data access.
Frontend and backend deployment.
Preview and production environments.
Local backend development.
Git-based deployment workflows.
For example, consider an application where users can register and create personal notes.
Without a managed development platform, you would typically need to configure the following:
Create a database.
Build authentication endpoints.
Implement access-control logic.
Develop backend APIs.
Connect the frontend to those APIs.
Configure hosting.
Set up CI/CD deployment.
Amplify provides an integrated workflow for these requirements.
How AWS Amplify Works
A simplified architecture looks like this:
User Browser
|
v
Next.js App
|
v
Amplify Client SDK
|
+-------+-------+
| |
v v
Authentication Data API
| |
v v
User Identity PostgreSQL
|
v
Access Policies
The frontend communicates with the backend through the Amplify client SDK.
Authentication identifies the current user, while database access policies determine which records that user can read or modify.
Amplify manages the backend infrastructure and deployment process.
2. Understand the Latest AWS Amplify Architecture
Before creating a project, it is important to understand that AWS Amplify has evolved through different generations.
Amplify Gen 1 uses an earlier CLI and backend workflow. Amplify Gen 2 introduced a TypeScript-based, code-first backend development experience.
The latest Amplify experience introduces a newer backend workflow with a simplified CLI, PostgreSQL database, managed authentication, and a generated data API.
These workflows should not be mixed.
Feature | Amplify Gen 1 | Amplify Gen 2 | Latest Amplify |
|---|
Backend definition | CLI and Amplify configuration | TypeScript | SQL migrations and configuration files |
Development approach | Configuration-driven | Code-first | Code-first |
Database options | AWS service integrations | Data and storage resources | Managed PostgreSQL |
Authentication | Amazon Cognito integration | Auth resources | Managed authentication |
Local development | Gen 1 tooling | Cloud sandbox | Local backend using Docker or Finch |
Deployment | Amplify CLI and Hosting | Amplify Hosting | Amplify CLI and Git deployment |
For this tutorial, we will use the latest Amplify workflow with the aws amplifygen3 commands.
Do not substitute older Gen 2 commands such as npx ampx sandbox or npm create amplify into this tutorial. Those commands belong to the earlier Gen 2 workflow.
3. Understand the Main Amplify Components
Before implementing the application, understand the services that make up the backend.
Amplify Hosting
Amplify Hosting manages the deployment and hosting of frontend applications.
It provides:
When connected to a supported Git repository, Amplify can build and deploy the application after code changes are pushed.
PostgreSQL Database
The latest Amplify backend provides a managed PostgreSQL database.
Developers define database structures using SQL migrations.
For example, a notes application can contain a table with the following fields:
Column | Data type | Purpose |
|---|
id | bigint | Unique note identifier |
owner_id | text | User who owns the note |
body | text | Note content |
created_at | timestamptz | Creation timestamp |
PostgreSQL provides familiar database capabilities such as indexes, constraints, transactions, and SQL queries.
Authentication
Authentication allows users to register, sign in, and manage their sessions.
The latest Amplify backend uses managed Better Auth for authentication.
It supports email and password authentication, social sign-in providers, and integration with Amazon Cognito user pools.
Data API
Amplify generates a data API from the database schema.
The API is compatible with PostgREST, allowing applications to access PostgreSQL data through a familiar query interface.
The frontend can use the Amplify backend client SDK to read and write records without creating a separate API server for every basic database operation.
Row-Level Security
Row-Level Security (RLS) controls which database records a user can access.
For example, a user should be able to read their own notes but should not be able to read another user's private notes.
RLS enforces these rules at the database level rather than relying only on frontend conditions.
This is an important security feature for multi-user applications.
4. Set Up the Development Environment
We will build a notes application using Next.js and AWS Amplify.
The application will support:
User registration.
User sign-in.
User-specific notes.
Adding notes.
Viewing notes.
Signing out.
Local development.
Preview deployment.
Production deployment.
Prerequisites
Install the following tools:
Tool | Requirement |
|---|
Node.js | 22.12 or later |
npm | 10 or later |
AWS CLI | Latest AWS CLI version 2 |
Docker or Finch | Running local container environment |
AWS account | Required permissions for Amplify |
Code editor | Visual Studio Code or another editor |
Verify Node.js:
node --version
Verify npm:
npm --version
Verify Docker:
docker info
Verify AWS CLI:
aws --version
Configure AWS credentials using an appropriate authentication method.
For example:
aws sso login
Check the current AWS identity:
aws sts get-caller-identity
Finally, verify that the Amplify Gen 3 commands are available:
aws amplifygen3 help
If the command is not available, update the AWS CLI to a version that includes the Amplify Gen 3 command group.
5. Create a Next.js Application
Start by creating a new Next.js project.
Run:
npx create-next-app@latest notes-app \
--ts \
--app \
--eslint \
--no-tailwind \
--no-src-dir \
--import-alias "@/*" \
--use-npm \
--yes
Move into the project directory:
cd notes-app
This command creates a Next.js application using TypeScript and the App Router.
Next, initialize Amplify:
aws amplifygen3 local init --type fullstack
The command initializes the Amplify backend structure locally.
It creates an amplify.jsonc configuration file, a migrations directory, and the required backend client packages.
At this stage, Amplify has not created the cloud application in your AWS account. The initialization only prepares the local project.
Understand the Project Structure
After initialization, the project will contain files similar to the following:
notes-app/
│
├── app/
│ ├── page.tsx
│ ├── layout.tsx
│ └── globals.css
│
├── lib/
│ └── backend.ts
│
├── migrations/
│
├── amplify.jsonc
│
├── next.config.ts
├── package.json
└── tsconfig.json
The important files are:
File or directory | Purpose |
|---|
amplify.jsonc | Amplify deployment and backend configuration |
migrations/ | SQL database migrations |
app/page.tsx | Main application page |
lib/backend.ts | Backend client initialization |
next.config.ts | Next.js configuration |
package.json | Application dependencies and scripts |
The migrations directory contains the SQL changes that define the database structure and security policies.
6. Create the PostgreSQL Database Table
Now create a database table to store user notes.
Amplify uses SQL migrations to manage database changes.
Create a migration file:
aws amplifygen3 local migration create \
--description "create notes"
Open the newly generated SQL file inside the migrations directory.
Add the following SQL:
create table public.notes (
id bigint generated always as identity primary key,
owner_id text not null default auth.uid(),
body text not null,
created_at timestamptz not null default now()
);
create index notes_owner_id_idx
on public.notes (owner_id);
alter table public.notes enable row level security;
create policy "own_select"
on public.notes
for select
to authenticated
using ((select auth.uid()) = owner_id);
create policy "own_insert"
on public.notes
for insert
to authenticated
with check ((select auth.uid()) = owner_id);
create policy "own_update"
on public.notes
for update
to authenticated
using ((select auth.uid()) = owner_id)
with check ((select auth.uid()) = owner_id);
create policy "own_delete"
on public.notes
for delete
to authenticated
using ((select auth.uid()) = owner_id);
grant select, insert, update, delete
on public.notes
to authenticated;
Understand the Database Structure
The id column uniquely identifies each note.
The owner_id column stores the identity of the user who created the note.
The body column contains the actual note content.
The created_at column records when the note was created.
The index on owner_id helps PostgreSQL locate records belonging to a particular user more efficiently.
Understand the Row-Level Security Policies
The following statement enables row-level security:
alter table public.notes enable row level security;
Without appropriate policies, enabling RLS prevents normal access to the protected table.
The SELECT policy is:
create policy "own_select"
on public.notes
for select
to authenticated
using ((select auth.uid()) = owner_id);
It allows an authenticated user to read only records where the stored owner_id matches their authenticated identity.
The INSERT policy is:
create policy "own_insert"
on public.notes
for insert
to authenticated
with check ((select auth.uid()) = owner_id);
It ensures that users can insert notes only when the owner_id matches their identity.
Similar policies protect update and delete operations.
This is important because hiding another user's records in the frontend is not sufficient security. A user could attempt to call the API directly.
Database-level authorization ensures that the same access rules apply regardless of how the request is made.
7. Connect Next.js to the Amplify Backend
The frontend needs a backend client to communicate with the database and authentication services.
Amplify provides the backend client package for this purpose.
The initialization process provides the backend URL and publishable key through environment variables.
Open next.config.ts and configure these values:
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;
These values are used to connect the frontend to the correct backend environment.
The backend URL identifies the API endpoint.
The publishable key identifies the public application configuration used by the client.
The publishable key is designed for browser use. It is not a replacement for authorization policies.
Never expose private database credentials or privileged keys that bypass RLS in frontend code.
Create the Backend Client
Create a file named lib/backend.ts.
Add:
import { createClient } from
"@aws-amplifygen3/backend-client-js";
let client:
ReturnType<typeof createClient> | undefined;
export function backend() {
client ??= createClient(
process.env.AMPLIFY_BACKEND_URL!,
process.env.AMPLIFY_BACKEND_PUBLISHABLE_KEY!
);
return client;
}
The createClient function initializes the connection to the Amplify backend.
The client is stored in a variable so the application can reuse the same initialized client instead of creating a new one every time backend() is called.
The non-null assertion operator tells TypeScript that the environment variables are expected to be available at runtime.
For a larger application, add explicit configuration validation so missing environment variables produce a clear startup error.
8. Build the Notes Application
Now implement the application interface.
Open app/page.tsx and replace its contents with the following code:
"use client";
import { useEffect, useState } from "react";
import { backend } from "@/lib/backend";
type Note = {
id: number;
body: string;
};
export default function Home() {
const [email, setEmail] = useState<string | null>(null);
const [notes, setNotes] = useState<Note[]>([]);
const [message, setMessage] = useState("");
async function loadNotes() {
const { data, error } = await backend()
.from("notes")
.select("id, body")
.order("id");
if (error) {
setMessage(error.message);
return;
}
setNotes(data ?? []);
}
useEffect(() => {
backend()
.auth
.getSession()
.then(({ data }) => {
setEmail(data.session?.user.email ?? null);
if (data.session) {
loadNotes();
}
});
}, []);
async function signUp(form: FormData) {
const { error } = await backend().auth.signUp.email({
email: String(form.get("email")),
password: String(form.get("password")),
});
if (error) {
setMessage(error.code ?? "Sign-up failed");
return;
}
location.reload();
}
async function signIn(form: FormData) {
const { error } = await backend().auth.signIn.email({
email: String(form.get("email")),
password: String(form.get("password")),
});
if (error) {
setMessage(error.code ?? "Sign-in failed");
return;
}
location.reload();
}
async function addNote(form: FormData) {
const body = String(form.get("body"));
const { error } = await backend()
.from("notes")
.insert({ body });
if (error) {
setMessage(error.message);
return;
}
setMessage("Note added successfully");
await loadNotes();
}
async function signOut() {
await backend().auth.signOut();
location.reload();
}
if (!email) {
return (
<main>
<h1>Notes Application</h1>
<form action={signUp}>
<input
name="email"
type="email"
placeholder="Email"
required
/>
<input
name="password"
type="password"
placeholder="Password"
required
minLength={8}
/>
<button type="submit">
Sign Up
</button>
<button formAction={signIn}>
Sign In
</button>
<p>{message}</p>
</form>
</main>
);
}
return (
<main>
<h1>Notes for {email}</h1>
<form action={addNote}>
<input
name="body"
placeholder="Enter a new note"
required
/>
<button type="submit">
Add Note
</button>
</form>
<ul>
{notes.map((note) => (
<li key={note.id}>
{note.body}
</li>
))}
</ul>
<p>{message}</p>
<button onClick={signOut}>
Sign Out
</button>
</main>
);
}
Understand the Application Code
The application uses React state to maintain the signed-in user's email, the notes collection, and status messages.
The loadNotes function reads records from the notes table.
const { data, error } = await backend()
.from("notes")
.select("id, body")
.order("id");
The query requests the note identifier and body, then sorts the results by ID.
The backend applies the current user's authorization rules. The application does not need to retrieve every user's notes and filter them manually.
The signUp function creates an account using email and password.
The signIn function authenticates an existing user.
The addNote function inserts a new record. The database supplies the owner_id through its default value, which is based on the authenticated user identity.
The signOut function ends the current session.
This example demonstrates the basic application workflow. A production application should additionally handle session-loading states, email verification requirements, password recovery, validation errors, duplicate submissions, and network failures.
9. Run the Application Locally
Once the database migration and frontend code are ready, start the local Amplify environment.
Run:
aws amplifygen3 local run
This command starts the local backend, applies the migration, and starts the development server.
You should see a local address similar to:
http://localhost:3000
Open the address in your browser.
Test the following workflow:
Register using an email address and password.
Sign in to the application.
Add a note.
Refresh the browser.
Verify that the note is still available.
Sign out.
Register another user and verify that the first user's notes are not visible.
The last step is especially important because it verifies that the database access policies are working.
Test User Data Isolation
Create two test accounts:
User 2 should not be able to read or modify User 1's records.
Test this through the application and, where possible, direct API requests using each user's authentication context.
If a user can access another user's records, review the RLS policies before proceeding.
10. Deploy the Application to AWS
After local testing, deploy the application to AWS.
The latest Amplify workflow supports deploying from the terminal or through a connected Git repository.
For this tutorial, we will use the CLI deployment workflow.
Run:
aws amplifygen3 deploy
The first deployment creates the Amplify application and its backend resources in your AWS account.
Amplify builds the application using the configuration in amplify.jsonc.
The deployment also applies the SQL migration to the preview environment.
When deployment finishes, the CLI displays a preview URL.
It may look similar to:
https://preview-xxxx--notes-app.amplify.app
The preview environment has its own backend branch and database.
This means users and notes created in your local environment do not automatically appear in the cloud preview environment.
Deploy to Production
After validating the preview deployment, deploy to production:
aws amplifygen3 deploy --env production
Amplify applies the production migration and deploys the application.
The production URL will resemble:
https://notes-app.amplify.app
After changing the application code, run the deployment command again to publish the updated version.
Always test the preview environment before deploying database or application changes to production.
11. Configure Git-Based Continuous Deployment
For team projects, Git-based deployment is generally more convenient than manually deploying every change from a developer's machine.
Connect the application repository to Amplify.
The workflow looks like this:
Developer
|
v
Git Commit
|
v
Git Repository
|
v
Amplify Build
|
v
Backend Migration
|
v
Frontend Build
|
v
Deployment
|
v
Live Website
When a supported Git branch receives a new commit, Amplify can build and deploy the application automatically.
For example:
Git branch | Purpose |
|---|
feature/notes | Feature development |
staging | Testing and validation |
production | Live application |
Amplify supports branch-based environments, allowing teams to test changes against separate backend branches.
Each environment has its own database and authentication configuration.
This helps prevent development data from mixing with production data.
Pull Request Previews
Pull request previews allow developers and reviewers to inspect changes before merging them into the main branch.
For example, a developer can create a new feature branch and open a pull request.
Amplify can create a preview deployment for that branch.
The reviewer can test the application before approving the change.
This is useful for teams working on large frontend applications where visual and functional testing is important.
12. Configure Environment Variables and Secrets
Applications often need configuration values that differ between development, staging, and production.
Examples include:
Environment variables provide a way to supply these values without hardcoding them into application source files.
For example:
const apiUrl = process.env.API_BASE_URL;
However, environment variables should not be treated as a secure storage location for every type of credential.
Never expose private keys, database passwords, or privileged access tokens to browser-side code.
The latest Amplify backend provides managed configuration and secret handling. Use the appropriate secret-management mechanism for sensitive values.
For frontend configuration, remember that values included in browser bundles are visible to users.
A good production practice is to separate public configuration from private server-side secrets.
13. Add Custom Domains and HTTPS
A deployed application initially receives an Amplify-provided domain.
For a production application, you may want to use a custom domain such as:
app.example.com
Amplify Hosting supports custom domain configuration.
The general process is:
Open the Amplify application in the AWS console.
Navigate to domain management.
Add your domain.
Configure the required DNS records.
Verify domain ownership.
Wait for certificate provisioning.
Test the application using the custom domain.
Amplify manages the SSL certificate integration for supported custom domain configurations.
Use HTTPS for all production application traffic.
If the application integrates with external authentication providers, update their callback and redirect URLs to include the production domain.
14. Understand Backend Environments and Database Migrations
One of the important features of the latest Amplify workflow is its integration between application deployments and backend changes.
Consider a situation where you add a new column to the notes table.
The database migration might contain:
alter table public.notes
add column category text;
The migration becomes part of the project repository.
When the application is deployed, Amplify applies the database migration to the target environment.
This keeps the database structure connected to the application version.
Why Separate Environments Matter
Suppose you have three environments:
Environment | Database | Purpose |
|---|
Development | Development database | Testing new changes |
Preview | Preview database | Reviewing application changes |
Production | Production database | Real users and business data |
A migration applied to one environment does not automatically copy its data into another environment.
Each environment maintains its own database and authentication users.
This separation is important for testing schema changes without affecting production records.
Database Migration Best Practices
Use the following practices:
Keep migrations in source control.
Review SQL changes before deployment.
Test migrations against realistic data.
Avoid unnecessary destructive changes.
Back up important production data.
Use backward-compatible schema changes where possible.
Plan how the application will behave during schema transitions.
For a major schema change, consider a staged migration.
For example, add a new column first, update the application to use it, migrate existing data, and remove the old column only after the new implementation is stable.
15. Monitor and Troubleshoot Amplify Applications
A production application needs monitoring after deployment.
When an application fails, developers should identify whether the issue comes from the frontend, backend, authentication, database, or deployment configuration.
Build Failures
If a deployment fails, inspect the build logs.
Common causes include:
Incorrect Node.js version.
Missing dependencies.
TypeScript compilation errors.
Invalid build configuration.
Missing environment variables.
Unsupported framework features.
Run the application build locally before deploying:
npm run build
Fix compilation errors before pushing changes.
Authentication Problems
If users cannot sign in, check:
Authentication configuration.
Email and password requirements.
Session handling.
Redirect URLs.
Browser network requests.
Backend authentication logs.
Database Access Errors
If a user can sign in but cannot retrieve records, review:
Table permissions.
RLS policies.
User identity mapping.
SQL migration status.
Data API configuration.
Authentication and authorization are different responsibilities.
A successful login does not automatically mean that the user has permission to access every database record.
Performance Monitoring
Monitor:
Application response time.
Database query latency.
API request failures.
Authentication failures.
Database resource utilization.
Frontend loading performance.
Use AWS monitoring services and application-level telemetry appropriate to the deployed architecture.
16. Common AWS Amplify Mistakes
Mixing Amplify Generations
Using commands from Gen 1, Gen 2, and the latest Amplify workflow in the same project can cause configuration and tooling problems.
Follow the documentation for the generation used by your application.
Exposing Private Credentials
Never place database passwords or privileged service credentials in frontend environment variables.
Browser-side code is accessible to users.
Ignoring Row-Level Security
A frontend filter is not a security boundary.
Always enforce user-specific access rules at the database or backend level.
Deploying Without Testing Migrations
A migration that works with an empty database may fail when applied to production data.
Test schema changes against realistic data before production deployment.
Using Production for Development
Do not use the production database for everyday feature development.
Use separate environments to isolate testing and development changes.
Ignoring Backend Costs
Managed infrastructure reduces operational work, but it does not mean the backend is free.
Review database usage, hosting charges, storage, data transfer, and any additional AWS services used by the application.
Also understand the latest Amplify backend's sleep and pause behavior. For example, an inactive backend can go to sleep, and the free plan has additional inactivity-pause behavior. This can affect applications that require predictable first-request latency.
Assuming Every Framework Feature Is Supported
Amplify supports several frontend frameworks, but individual server-side rendering features and framework versions have their own compatibility requirements.
Check the current framework support documentation before selecting a production architecture.
17. AWS Amplify Advantages and Limitations
Advantages
Simplified full-stack development: Developers can manage frontend hosting and backend resources through an integrated workflow.
Faster development: Authentication, database access, and hosting can be configured without building every supporting service manually.
Code-based infrastructure: Backend configuration and database migrations can be maintained in source control.
Separate environments: Preview and production environments help teams test changes safely.
Managed database: Developers do not need to manage the underlying PostgreSQL server infrastructure.
Git-based deployment: Application changes can be built and deployed automatically after code commits.
User-level authorization: PostgreSQL RLS provides database-level control over record access.
Limitations
Platform dependency: Applications using Amplify-specific backend features may require changes when moving to another platform.
Framework compatibility: Not every framework feature or version is supported in every hosting configuration.
Database design responsibility: Developers still need to understand PostgreSQL, indexing, transactions, and query performance.
Cost management: Managed services still generate infrastructure and usage costs.
Backend customization: Applications requiring unusual infrastructure or complex networking may need additional AWS services.
Operational awareness: Teams must understand environment isolation, database migrations, permissions, and deployment behavior.
Conclusion
AWS Amplify provides an integrated approach to building and deploying full-stack applications. Developers can define a PostgreSQL database, configure authentication, enforce data access rules, connect a frontend, and deploy the application through a managed workflow.
In this tutorial, we created a Next.js notes application with user registration, sign-in, database operations, and row-level security. We also explored local development, preview deployments, production environments, Git-based deployment, and custom domains.
The most important part of building a secure Amplify application is understanding that authentication and authorization are separate. Authentication identifies the user, while database policies determine which records that user can access.
For a small application or a new product, Amplify can reduce the amount of infrastructure work required to get started. For larger systems, evaluate its database capabilities, hosting requirements, cost model, and integration needs before choosing it as the primary application platform.
Join the conversation! Your thoughts help the community grow.