Amplify Gen 1 vs Gen 2

AWS Amplify Gen 2 is a complete rewrite of the Amplify experience. Understanding the differences will help you navigate documentation and avoid confusion.

📌
This Course Uses Gen 2

This course exclusively teaches Amplify Gen 2. If you encounter older tutorials or documentation using amplify init or GraphQL schema files, those are Gen 1 patterns.

The Evolution of Amplify

AWS Amplify was originally released in 2017 and has evolved significantly. In late 2023, AWS announced Amplify Gen 2, which represents a fundamental shift in how you define and manage your backend.

Aspect Gen 1 (Legacy) Gen 2 (Current)
Backend Definition CLI prompts & GraphQL schema files TypeScript code in amplify/ folder
CLI Command amplify ampx
Initialization amplify init npx ampx sandbox
Schema Language GraphQL SDL (.graphql files) TypeScript with schema builder
Type Safety Generated after build Built-in, real-time
Infrastructure CloudFormation templates AWS CDK (under the hood)
Local Development Mock server (amplify mock) Sandbox (ampx sandbox)

Key Differences Explained

1. TypeScript-First Approach

The biggest change is how you define your backend. In Gen 1, you answered CLI prompts and wrote GraphQL schema files:

# Gen 1: GraphQL Schema (schema.graphql)
type Todo @model @auth(rules: [{ allow: owner }]) {
  id: ID!
  content: String!
  completed: Boolean
}

In Gen 2, you write TypeScript code that's fully type-safe:

// Gen 2: TypeScript Schema (amplify/data/resource.ts)
import { a, defineData, type ClientSchema } from '@aws-amplify/backend';

const schema = a.schema({
  Todo: a.model({
    content: a.string().required(),
    completed: a.boolean().default(false),
  }).authorization(allow => [allow.owner()]),
});

export type Schema = ClientSchema<typeof schema>;
export const data = defineData({ schema });
Why TypeScript is Better

TypeScript gives you autocomplete, compile-time error checking, and refactoring support. If you make a typo in your schema, your IDE shows an error immediately.

2. The CLI Change: amplifyampx

Gen 2 uses a new CLI called ampx. Here's a comparison of common commands:

Action Gen 1 Command Gen 2 Command
Initialize project amplify init npx ampx sandbox
Add authentication amplify add auth Write amplify/auth/resource.ts
Add data/API amplify add api Write amplify/data/resource.ts
Push changes amplify push Automatic (sandbox watches files)
Deploy amplify publish Git push to connected repo
Generate types amplify codegen npx ampx generate graphql-client-code

3. Sandbox vs Mock

Sandbox

A personal development environment that deploys real AWS resources to your account. Each developer gets their own isolated backend with a unique identifier.

In Gen 1, amplify mock created a local simulation of your backend. In Gen 2, ampx sandbox creates actual AWS resources but isolated per developer:

npx ampx sandbox

The sandbox:

  • Deploys real AWS resources (DynamoDB tables, Cognito pools, etc.)
  • Watches your amplify/ folder for changes
  • Automatically redeploys when you modify resources
  • Creates an amplify_outputs.json file for your frontend
  • Is isolated to your AWS account and branch
⚠️
Sandbox Uses Real AWS Resources

Unlike Gen 1's mock, sandbox creates actual AWS resources. While covered by free tier for small usage, remember to delete sandboxes when not in use with npx ampx sandbox delete.

4. CDK Under the Hood

AWS CDK (Cloud Development Kit)

An open-source framework that lets you define cloud infrastructure using programming languages like TypeScript. Gen 2 uses CDK internally.

Gen 1 used CloudFormation templates directly, which were complex and hard to customize. Gen 2 is built on AWS CDK, giving you the ability to extend and customize resources when needed:

// You can access the underlying CDK constructs if needed
import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource';
import { data } from './data/resource';

const backend = defineBackend({
  auth,
  data,
});

// Access CDK constructs for advanced customization
const authStack = backend.auth.stack;
// Add custom CDK code here...

Why AWS Made This Change

AWS rebuilt Amplify Gen 2 to address common developer feedback:

  1. Better Developer Experience – TypeScript provides autocomplete and error checking
  2. Version Control Friendly – Everything is code, making PRs and reviews easy
  3. Customization – CDK access allows you to extend beyond Amplify's defaults
  4. Faster Iteration – Sandbox with hot-reload makes development faster
  5. Team Collaboration – Each developer can have their own sandbox

Identifying Gen 1 vs Gen 2 Code

When searching online, you might find outdated Gen 1 tutorials. Here's how to tell them apart:

🔴 Gen 1 Indicators

  • Uses amplify init, amplify add, amplify push
  • Has schema.graphql or *.graphql files
  • References aws-exports.js
  • Uses @model, @auth GraphQL directives
  • Has an amplify/#current-cloud-backend folder

🟢 Gen 2 Indicators

  • Uses ampx sandbox, ampx generate
  • Has amplify/ folder with resource.ts files
  • References amplify_outputs.json
  • Uses defineAuth, defineData, a.schema()
  • Imports from @aws-amplify/backend

Summary

  • Gen 2 is the current version of Amplify (released late 2023)
  • Uses TypeScript code instead of GraphQL schemas and CLI prompts
  • The CLI command changed from amplify to ampx
  • Sandbox replaces mock with real AWS resources per developer
  • Built on AWS CDK for better customization
  • Look for Gen 2 indicators when following tutorials