AWS Amplify Gen2
Build and deploy full-stack applications using AWS Amplify Gen2's TypeScript
code-first approach. This skill covers backend resource creation, frontend
integration across 8 frameworks, and deployment workflows.
Prerequisites
- Node.js ^18.19.0 || ^20.6.0 || >=22 and npm
- AWS credentials configured (
aws sts get-caller-identity succeeds)
- For sandbox:
npx ampx --version returns a valid version
- For mobile: Platform-specific tooling (Xcode, Android Studio, Flutter SDK)
Defaults & Assumptions
When the user does not specify a framework:
- Web: You SHOULD default to React (Vite) and explain the choice.
- Mobile: You MUST ask which platform the user wants (Flutter,
Swift, Android, or React Native). There is no universal mobile default.
- Neither specified: If the user says "build an app" without clarifying web
vs. mobile, you MUST ask before proceeding.
- Backend only: If only backend changes are requested and no frontend
framework is mentioned, skip the frontend integration step entirely.
When the user does not specify tooling or strategy:
- Package manager: You SHOULD default to npm unless the user
specifies yarn or pnpm.
- Language: You SHOULD default to TypeScript. Gen2 backends are
TypeScript-only; frontends SHOULD follow the project's existing language.
- Next.js: You SHOULD default to App Router unless the user
specifies Pages Router.
- React Native: Ask the user whether they use Expo or bare
React Native CLI.
- Auth: You MUST ask which login method the user wants
(email/password, social login, SAML, passwordless, etc.). Do not assume a default.
- Data authorization: default to
publicApiKey
(allow.publicApiKey()) — this is the starter template default. When
auth is added, switch to owner-based (allow.owner()) with
defaultAuthorizationMode: 'userPool'.
Quick Start — Route to the Right Reference
Step 0: Read Core Reference (ALWAYS)
You MUST read the core reference for your target platform before
reading any other reference file. These contain Gen2 detection,
Amplify.configure() placement per framework, sandbox commands, required
packages, and directory structure rules — patterns needed for all tasks,
not just new projects.
- Web (React, Next.js, Vue, Angular, React Native): You MUST read
core-web.md
- Mobile (Flutter, Swift, Android): You MUST read
core-mobile.md
- Backend only (no frontend work): Skip to Step 1.
Step 1: Identify the Task Type
| Task |
Go To |
| Create a new project |
→ scaffolding.md, then Step 2 and/or Step 3 |
| Add or modify a backend feature |
→ Step 2 (Backend Features) |
| Connect frontend to existing backend |
→ Step 3 (Frontend Integration) |
| Deploy the application |
→ deployment.md |
Step 2: Backend Features
You MUST read the corresponding reference for each backend feature:
| Feature |
Reference |
When to Use |
| Authentication |
auth-backend.md |
Email/password, social login, MFA, SAML/OIDC |
| Data Models |
data-backend.md |
GraphQL schema, DynamoDB, relationships, auth rules |
| File Storage |
storage-backend.md |
S3 uploads/downloads, access rules |
| Functions & API |
functions-and-api.md |
Lambda, custom resolvers, REST/HTTP APIs, calling from client |
| AI Features |
ai.md |
Conversation, generation, AI tools via Bedrock (backend config + React/Next.js frontend) |
| Geo, PubSub, CDK |
advanced-features.md |
Backend-only: custom CDK stacks, overrides, custom outputs. Backend + frontend: Geo, PubSub, Face Liveness |
Each backend feature file is self-contained. Load only what you need.
Routing note: These files apply for both adding and modifying
features. Route to the same file whether the user says "add auth" or
"change auth config" — each reference covers the full define surface.
Step 3: Frontend Integration
After configuring backend resources, connect the frontend. Choose by
platform and feature:
Web (React, Next.js, Vue, Angular, React Native):
| Feature |
Reference |
| Auth UI & flows |
auth-web.md |
| Data CRUD & subscriptions |
data-web.md |
| Storage upload/download |
storage-web.md |
Mobile (Flutter, Swift, Android):
| Feature |
Reference |
| Auth UI & flows |
auth-mobile.md |
| Data CRUD & subscriptions |
data-mobile.md |
| Storage upload/download |
storage-mobile.md |
Note: AI and Functions frontend patterns are included in
ai.md and
functions-and-api.md respectively —
they are not split into separate web/mobile files.
Core Concepts
Amplify Gen2 Architecture
- Code-first: All backend resources defined in TypeScript under
amplify/
- Main config:
amplify/backend.ts imports and combines all resources via
defineBackend()
- Resource files:
amplify/auth/resource.ts, amplify/data/resource.ts,
amplify/storage/resource.ts, amplify/functions/<name>/resource.ts
- Generated output:
amplify_outputs.json — consumed by frontend
Amplify.configure(). Gitignored — generated by npx ampx sandbox
(local dev) or npx ampx pipeline-deploy (CI/CD), never committed.
Directory Structure
project-root/
├── amplify/
│ ├── backend.ts # defineBackend({ auth, data, ... })
│ ├── auth/resource.ts # defineAuth({ ... })
│ ├── data/resource.ts # defineData({ schema })
│ ├── storage/resource.ts # defineStorage({ ... })
│ └── functions/
│ └── my-func/
│ ├── resource.ts # defineFunction({ ... })
│ └── handler.ts # export const handler = ...
├── src/ # Frontend code
├── amplify_outputs.json # Generated — DO NOT edit or commit (gitignored)
└── package.json
Key APIs
| Package |
Purpose |
@aws-amplify/backend |
defineAuth, defineData, defineStorage, defineFunction, defineBackend |
aws-amplify |
Frontend: Amplify.configure(), generateClient(), auth/data/storage APIs |
@aws-amplify/ui-react |
Pre-built UI: <Authenticator>, <StorageBrowser> |
@aws-amplify/ui-react-ai |
AI UI: <AIConversation>, useAIConversation |
Documentation & Resource Verification
When you need AWS documentation (advanced CDK constructs, service limits,
provider-specific auth config):
- If AWS documentation tools are available (e.g., via AWS MCP), you SHOULD
use them to search and retrieve relevant documentation pages.
- If AWS documentation tools are unavailable, you MUST fall back to web
search or the
aws CLI for resource verification.
Why conditional: Amplify Gen2 is code-first — the primary workflow is
editing TypeScript files and running npx ampx commands. AWS MCP tools
are useful for post-deployment verification but are not required.
Security Considerations
- Use
secret() for all credentials and API keys — never hardcode or use plain environment variables for sensitive values
- Review
allow.guest() exposure carefully — guest access is enabled by default and grants unauthenticated users access to IAM-authorized resources
- Scope IAM policies to specific resource ARNs — avoid
resources: ['*'] in production
- Never log secrets or include them in error messages
- Enable CloudTrail and CloudWatch alarms for monitoring Amplify-deployed resources; enable access logging on S3, AppSync, and API Gateway
- Configure security headers for web apps — set CSP, HSTS, X-Frame-Options, and X-Content-Type-Options via
customHeaders in amplify.yml
- Attach AWS WAF to public-facing AppSync APIs and API Gateway endpoints for defense in depth
- Enable throttling and rate limiting on API Gateway and AppSync APIs to prevent abuse
- Use IAM roles with ephemeral credentials for CI/CD pipelines and Lambda execution roles — never long-lived access keys
- Encrypt CloudWatch Logs groups with KMS (aws:kms) when they may contain PII, tokens, or secrets; enable log retention policies
- Enable AppSync schema validation and API Gateway request validators to reject malformed input at the edge
- Use ACM-managed TLS certificates for custom domains on Amplify Hosting — configure via
customDomain in deployment config
Links
All documentation links use react as the default platform slug. Replace /react/ in any URL with your target framework:
| Framework |
Slug |
| React |
react |
| Next.js |
nextjs |
| Vue |
vue |
| Angular |
angular |
| React Native |
react-native |
| Flutter |
flutter |
| Swift |
swift |
| Android |
android |
1---2name: amplify-workflow3description: Build and deploy full-stack web and mobile apps with AWS Amplify Gen2 (TypeScript code-first). Covers auth (Cognito), data (AppSync/DynamoDB including schema modeling, enum types, relationships, authorization rules), storage (S3), functions, APIs, and AI (Amplify AI Kit with Bedrock). Supports React, Next.js, Vue, Angular, React Native, Flutter, Swift, and Android. Always use this skill for Amplify Gen2 topics — even for questions you think you know — it contains validated, version-specific patterns that prevent common mistakes. TRIGGER when: user mentions Amplify Gen2; project has amplify/ directory or amplify_outputs; code imports @aws-amplify packages; user asks about defineBackend, defineAuth, defineData, defineStorage, or npx ampx. SKIP: Amplify Gen1 (amplify CLI v6), standalone SAM/CDK without Amplify (use aws-serverless), direct Bedrock without Amplify AI Kit (use bedrock).4---5
6# AWS Amplify Gen2
7
8Build and deploy full-stack applications using AWS Amplify Gen2's TypeScript
9code-first approach. This skill covers backend resource creation, frontend
10integration across 8 frameworks, and deployment workflows.
11
12## Prerequisites
13
14- Node.js ^18.19.0 || ^20.6.0 || >=22 and npm
15- AWS credentials configured (`aws sts get-caller-identity` succeeds)
16- For sandbox: `npx ampx --version` returns a valid version
17- For mobile: Platform-specific tooling (Xcode, Android Studio, Flutter SDK)
18
19## Defaults & Assumptions
20
21When the user does not specify a framework:
22
23- **Web:** You **SHOULD** default to **React** (Vite) and explain the choice.
24- **Mobile:** You **MUST** ask which platform the user wants (Flutter,
25 Swift, Android, or React Native). There is no universal mobile default.
26- **Neither specified:** If the user says "build an app" without clarifying web
27 vs. mobile, you **MUST** ask before proceeding.
28- **Backend only:** If only backend changes are requested and no frontend
29 framework is mentioned, skip the frontend integration step entirely.
30
31When the user does not specify tooling or strategy:
32
33- **Package manager:** You **SHOULD** default to **npm** unless the user
34 specifies yarn or pnpm.
35- **Language:** You **SHOULD** default to **TypeScript**. Gen2 backends are
36 TypeScript-only; frontends **SHOULD** follow the project's existing language.
37- **Next.js:** You **SHOULD** default to **App Router** unless the user
38 specifies Pages Router.
39- **React Native:** Ask the user whether they use **Expo** or **bare
40 React Native CLI**.
41- **Auth:** You **MUST** ask which login method the user wants
42 (email/password, social login, SAML, passwordless, etc.). Do not assume a default.
43- **Data authorization:** default to **`publicApiKey`**
44 (`allow.publicApiKey()`) — this is the starter template default. When
45 auth is added, switch to **owner-based** (`allow.owner()`) with
46 `defaultAuthorizationMode: 'userPool'`.
47
48## Quick Start — Route to the Right Reference
49
50### Step 0: Read Core Reference (ALWAYS)
51
52You **MUST** read the core reference for your target platform **before
53reading any other reference file**. These contain Gen2 detection,
54`Amplify.configure()` placement per framework, sandbox commands, required
55packages, and directory structure rules — patterns needed for **all** tasks,
56not just new projects.
57
58- **Web** (React, Next.js, Vue, Angular, React Native): You **MUST** read
59 [core-web.md](references/core-web.md)
60- **Mobile** (Flutter, Swift, Android): You **MUST** read
61 [core-mobile.md](references/core-mobile.md)
62- **Backend only** (no frontend work): Skip to Step 1.
63
64### Step 1: Identify the Task Type
65
66| Task | Go To |
67| ---------------------------------------- | ------------------------------------------------------------------------ |
68| **Create a new project** | → [scaffolding.md](references/scaffolding.md), then Step 2 and/or Step 3 |
69| **Add or modify a backend feature** | → Step 2 (Backend Features) |
70| **Connect frontend to existing backend** | → Step 3 (Frontend Integration) |
71| **Deploy the application** | → [deployment.md](references/deployment.md) |
72
73### Step 2: Backend Features
74
75You **MUST** read the corresponding reference for each backend feature:
76
77| Feature | Reference | When to Use |
78| ---------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
79| Authentication | [auth-backend.md](references/auth-backend.md) | Email/password, social login, MFA, SAML/OIDC |
80| Data Models | [data-backend.md](references/data-backend.md) | GraphQL schema, DynamoDB, relationships, auth rules |
81| File Storage | [storage-backend.md](references/storage-backend.md) | S3 uploads/downloads, access rules |
82| Functions & API | [functions-and-api.md](references/functions-and-api.md) | Lambda, custom resolvers, REST/HTTP APIs, calling from client |
83| AI Features | [ai.md](references/ai.md) | Conversation, generation, AI tools via Bedrock _(backend config + React/Next.js frontend)_ |
84| Geo, PubSub, CDK | [advanced-features.md](references/advanced-features.md) | Backend-only: custom CDK stacks, overrides, custom outputs. Backend + frontend: Geo, PubSub, Face Liveness |
85
86Each backend feature file is self-contained. Load only what you need.
87
88> **Routing note:** These files apply for both **adding** and **modifying**
89> features. Route to the same file whether the user says "add auth" or
90> "change auth config" — each reference covers the full define surface.
91
92### Step 3: Frontend Integration
93
94After configuring backend resources, connect the frontend. Choose by
95platform and feature:
96
97**Web** (React, Next.js, Vue, Angular, React Native):
98
99| Feature | Reference |
100| ------------------------- | ------------------------------------------- |
101| Auth UI & flows | [auth-web.md](references/auth-web.md) |
102| Data CRUD & subscriptions | [data-web.md](references/data-web.md) |
103| Storage upload/download | [storage-web.md](references/storage-web.md) |
104
105**Mobile** (Flutter, Swift, Android):
106
107| Feature | Reference |
108| ------------------------- | ------------------------------------------------- |
109| Auth UI & flows | [auth-mobile.md](references/auth-mobile.md) |
110| Data CRUD & subscriptions | [data-mobile.md](references/data-mobile.md) |
111| Storage upload/download | [storage-mobile.md](references/storage-mobile.md) |
112
113> **Note:** AI and Functions frontend patterns are included in
114> [ai.md](references/ai.md) and
115> [functions-and-api.md](references/functions-and-api.md) respectively —
116> they are **not** split into separate web/mobile files.
117
118## Core Concepts
119
120### Amplify Gen2 Architecture
121
122- **Code-first:** All backend resources defined in TypeScript under `amplify/`
123- **Main config:** `amplify/backend.ts` imports and combines all resources via
124 `defineBackend()`
125- **Resource files:** `amplify/auth/resource.ts`, `amplify/data/resource.ts`,
126 `amplify/storage/resource.ts`, `amplify/functions/<name>/resource.ts`
127- **Generated output:** `amplify_outputs.json` — consumed by frontend
128 `Amplify.configure()`. **Gitignored** — generated by `npx ampx sandbox`
129 (local dev) or `npx ampx pipeline-deploy` (CI/CD), never committed.
130
131### Directory Structure
132
133```
134project-root/
135├── amplify/
136│ ├── backend.ts # defineBackend({ auth, data, ... })
137│ ├── auth/resource.ts # defineAuth({ ... })
138│ ├── data/resource.ts # defineData({ schema })
139│ ├── storage/resource.ts # defineStorage({ ... })
140│ └── functions/
141│ └── my-func/
142│ ├── resource.ts # defineFunction({ ... })
143│ └── handler.ts # export const handler = ...
144├── src/ # Frontend code
145├── amplify_outputs.json # Generated — DO NOT edit or commit (gitignored)
146└── package.json
147```
148
149### Key APIs
150
151| Package | Purpose |
152| -------------------------- | ------------------------------------------------------------------------------ |
153| `@aws-amplify/backend` | `defineAuth`, `defineData`, `defineStorage`, `defineFunction`, `defineBackend` |
154| `aws-amplify` | Frontend: `Amplify.configure()`, `generateClient()`, auth/data/storage APIs |
155| `@aws-amplify/ui-react` | Pre-built UI: `<Authenticator>`, `<StorageBrowser>` |
156| `@aws-amplify/ui-react-ai` | AI UI: `<AIConversation>`, `useAIConversation` |
157
158## Documentation & Resource Verification
159
160When you need AWS documentation (advanced CDK constructs, service limits,
161provider-specific auth config):
162
1631. **If AWS documentation tools are available (e.g., via AWS MCP)**, you **SHOULD**
164 use them to search and retrieve relevant documentation pages.
1652. **If AWS documentation tools are unavailable**, you **MUST** fall back to web
166 search or the `aws` CLI for resource verification.
167
168> **Why conditional:** Amplify Gen2 is code-first — the primary workflow is
169> editing TypeScript files and running `npx ampx` commands. AWS MCP tools
170> are useful for post-deployment verification but are **not** required.
171
172## Security Considerations
173
174- Use `secret()` for all credentials and API keys — never hardcode or use plain environment variables for sensitive values
175- Review `allow.guest()` exposure carefully — guest access is enabled by default and grants unauthenticated users access to IAM-authorized resources
176- Scope IAM policies to specific resource ARNs — avoid `resources: ['*']` in production
177- Never log secrets or include them in error messages
178- Enable CloudTrail and CloudWatch alarms for monitoring Amplify-deployed resources; enable access logging on S3, AppSync, and API Gateway
179- Configure security headers for web apps — set CSP, HSTS, X-Frame-Options, and X-Content-Type-Options via `customHeaders` in `amplify.yml`
180- Attach AWS WAF to public-facing AppSync APIs and API Gateway endpoints for defense in depth
181- Enable throttling and rate limiting on API Gateway and AppSync APIs to prevent abuse
182- Use IAM roles with ephemeral credentials for CI/CD pipelines and Lambda execution roles — never long-lived access keys
183- Encrypt CloudWatch Logs groups with KMS (aws:kms) when they may contain PII, tokens, or secrets; enable log retention policies
184- Enable AppSync schema validation and API Gateway request validators to reject malformed input at the edge
185- Use ACM-managed TLS certificates for custom domains on Amplify Hosting — configure via `customDomain` in deployment config
186
187## Links
188
189> All documentation links use `react` as the default platform slug. Replace `/react/` in any URL with your target framework:
190
191| Framework | Slug |
192| ------------ | -------------- |
193| React | `react` |
194| Next.js | `nextjs` |
195| Vue | `vue` |
196| Angular | `angular` |
197| React Native | `react-native` |
198| Flutter | `flutter` |
199| Swift | `swift` |
200| Android | `android` |
201
202- [Amplify Docs for LLMs](https://docs.amplify.aws/ai/llms.txt)
203- [Amplify Docs](https://docs.amplify.aws/)
204- [Gen2 Docs](https://docs.amplify.aws/react/)
205- [Getting Started](https://docs.amplify.aws/react/start/)
206- [Quickstart](https://docs.amplify.aws/react/start/quickstart/)
207- [Account Setup](https://docs.amplify.aws/react/start/account-setup/)
208- [How Amplify Works](https://docs.amplify.aws/react/how-amplify-works/)
209- [Core Concepts](https://docs.amplify.aws/react/how-amplify-works/concepts/)
210- [Build a Backend](https://docs.amplify.aws/react/build-a-backend/)
211- [Deploy and Host](https://docs.amplify.aws/react/deploy-and-host/)
212- [Troubleshooting](https://docs.amplify.aws/react/build-a-backend/troubleshooting/)
213- [CLI Commands](https://docs.amplify.aws/react/reference/cli-commands/)
214- [Amplify Outputs](https://docs.amplify.aws/react/reference/amplify_outputs/)
215- [Project Structure](https://docs.amplify.aws/react/reference/project-structure/)
216- [Amplify UI](https://ui.docs.amplify.aws/)