You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Mistral**: `'Mistral Large 2'`, `'Mistral Large'`, `'Mistral Small'`
15
+
Key constraint: `a.generation()` routes only support Anthropic (Claude) models. `a.conversation()` routes work with any supported model.
18
16
19
17
For models not in the supported list, use the raw escape hatch: `aiModel: { resourcePath: '<bedrock-model-id>' }`.
20
18
21
19
Availability depends on the AWS region and Bedrock model access enablement.
22
20
23
-
> **Note:**`a.generation()` routes only support Anthropic (Claude) models. `a.conversation()` routes work with any supported model.
21
+
### Bedrock Model Access
22
+
23
+
Some older or restricted models require explicit enablement in the AWS Bedrock console (Model access). On-demand foundation models (Claude Sonnet 4+, Nova) are available immediately. Amplify uses global inference profiles for cross-region model access.
24
+
25
+
If you get `AccessDeniedException: Could not access the model with the specified model ID`, check **Bedrock → Model access** in your region.
24
26
25
27
## Backend: Conversation Routes
26
28
@@ -33,7 +35,7 @@ import { a, type ClientSchema } from '@aws-amplify/backend';
33
35
34
36
const schema =a.schema({
35
37
chat: a.conversation({
36
-
aiModel: a.ai.model('Claude 3.5 Sonnet v2'),
38
+
aiModel: a.ai.model('Claude Sonnet 4.5'),
37
39
systemPrompt: 'You are a helpful assistant.',
38
40
})
39
41
.authorization(allow=>allow.owner()),
@@ -44,12 +46,10 @@ const schema = a.schema({
44
46
45
47
Use `a.generation()` for single-turn (stateless) inference.
46
48
47
-
> **MUST:** Only Anthropic (Claude) models support `a.generation()` routes. Non-Anthropic models (Amazon Nova, Meta Llama, Cohere, Mistral) work with `a.conversation()` only.
48
-
49
49
```typescript
50
50
const schema =a.schema({
51
51
summarize: a.generation({
52
-
aiModel: a.ai.model('Claude 3.5 Sonnet v2'),
52
+
aiModel: a.ai.model('Claude Sonnet 4.5'),
53
53
systemPrompt: 'Summarize the provided text concisely.',
**Authorization constraints (these cause TypeError at CDK assembly if violated):**
63
63
64
-
-**Conversation routes** (`a.conversation()`) **MUST** use `allow.owner()` authorization — `allow.authenticated()` and other non-owner strategies throw a TypeError at CDK assembly time (before deployment even begins).
65
-
-**Generation routes** (`a.generation()`) **MUST** use non-owner authorization (`allow.authenticated()`, `allow.guest()`, `allow.group()`, or `allow.publicApiKey()`) — `allow.owner()` throws a TypeError at CDK assembly time (before deployment even begins).
64
+
-**Conversation routes** (`a.conversation()`) require `allow.owner()` authorization — `allow.authenticated()` and other non-owner strategies throw a TypeError at CDK assembly time.
65
+
-**Generation routes** (`a.generation()`) require non-owner authorization (`allow.authenticated()`, `allow.guest()`, `allow.group()`, or `allow.publicApiKey()`) — `allow.owner()` throws a TypeError at CDK assembly time.
66
66
67
67
These constraints are asymmetric and frequently confused. Getting them wrong
68
68
causes the CDK synthesis to fail with a non-obvious TypeError.
69
69
70
+
> **Security:** Conversation history sent to Amazon Bedrock may contain PII. Do not log full request/response payloads in production. Enable CloudWatch Logs encryption (KMS) and set appropriate retention policies for any logs that may capture inference data.
71
+
70
72
### Backend Integration
71
73
72
74
AI conversation and generation routes are part of your data schema. Import into `amplify/backend.ts`:
@@ -88,7 +90,7 @@ import { myToolFunc } from '../functions/my-tool/resource';
88
90
89
91
const schema =a.schema({
90
92
chat: a.conversation({
91
-
aiModel: a.ai.model('Claude 3.5 Sonnet v2'),
93
+
aiModel: a.ai.model('Claude Sonnet 4.5'),
92
94
systemPrompt: 'You are a helpful assistant with tool access.',
93
95
tools: [
94
96
{
@@ -170,7 +172,7 @@ Pagination: use `limit` and `nextToken` parameters on `.list()`.
170
172
171
173
Subscribe to streaming responses for real-time token delivery:
172
174
173
-
In React, **MUST**wrap in `useEffect` and return the cleanup function:
175
+
In React, wrap in `useEffect` and return the cleanup function:
174
176
175
177
```tsx
176
178
useEffect(() => {
@@ -189,18 +191,6 @@ useEffect(() => {
189
191
190
192
## Pitfalls
191
193
192
-
-**Conversation auth MUST be `allow.owner()`:** Using
193
-
`allow.authenticated()` or any other non-owner strategy on
194
-
`a.conversation()` throws a TypeError at CDK assembly time.
195
-
-**Generation auth MUST NOT be `allow.owner()`:** Using
196
-
`allow.owner()` on `a.generation()` throws a TypeError at CDK assembly
197
-
time. Use `allow.authenticated()`, `allow.guest()`, or `allow.group()`.
198
-
-**Missing AI route in data schema:** The conversation or generation
199
-
route **MUST** be defined in your `a.schema()` — without it, the
200
-
frontend client has no AI endpoint to call.
201
-
-**Model availability:** Not all Bedrock models are enabled by default —
202
-
you **MUST** enable model access in the AWS console (Bedrock → Model
203
-
access) before using a model in `a.ai.model()`.
204
194
-**Message content structure:** Both `sendMessage('Hello')` (string) and
205
195
`sendMessage({ content: [{ text: 'Hello' }] })` (object) are valid. Use
206
196
the object form when sending images or tool results.
Set secrets via CLI: `echo "<value>" | npx ampx sandbox secret set GOOGLE_CLIENT_ID`.
126
-
For provider-specific OAuth setup guides, **SHOULD**consult AWS
127
-
documentation via available tools; when unavailable, **MUST**use web
127
+
Set secrets via CLI: `echo -n "<value>" | npx ampx sandbox secret set MY_OAUTH_CLIENT_ID`. (The documented approach uses an interactive prompt; piping with `echo -n` is a practical alternative for scripts.)
128
+
For provider-specific OAuth setup guides, consult AWS
129
+
documentation via available tools; when unavailable, use web
128
130
search or AWS CLI.
129
131
130
132
## SAML / OIDC (Enterprise)
131
133
132
-
OIDC providers are configured directly in `externalProviders`:
134
+
OIDC providers are configured inside `loginWith.externalProviders`:
**SAML** is NOT supported in `defineAuth` — the `ExternalProviderSpecificFactoryProps` type has no `saml` property. The lower-level `auth-construct` package supports SAML, but it was never wired up to the high-level API. Use CDK escape hatches via `backend.auth.resources` to configure SAML providers:
@@ -182,21 +191,51 @@ import { defineFunction } from '@aws-amplify/backend';
1.**Separate DynamoDB table** — create via CDK (not `defineData`) to avoid stack coupling.
211
+
212
+
## Guest (Unauthenticated) Access
186
213
187
214
Guest access is **enabled by default** in Amplify Gen2 — the Cognito Identity Pool is created with `allowUnauthenticatedIdentities: true` automatically.
188
215
189
-
To use guest access in your data models, set `defaultAuthorizationMode` to `'iam'`:
216
+
To use guest access in your data models, set `defaultAuthorizationMode` to `'iam'` and add `allow.guest()` authorization rules:
190
217
191
218
```typescript
219
+
const schema =a.schema({
220
+
Todo: a.model({
221
+
content: a.string(),
222
+
}).authorization(allow=> [
223
+
allow.guest().to(['read']), // unauthenticated users can read
224
+
allow.owner(), // owners can CRUD
225
+
]),
226
+
});
227
+
192
228
exportconst data =defineData({
193
229
schema,
194
230
authorizationModes: {
195
-
defaultAuthorizationMode: 'iam',
231
+
defaultAuthorizationMode: 'iam', // required for guest access
232
+
apiKeyAuthorizationMode: { expiresInDays: 7 }, // optional alternative
196
233
},
197
234
});
198
235
```
199
236
237
+
> **Security:** Guest access grants unauthenticated users IAM-authorized access. For production, explicitly evaluate whether guest access is needed and prefer `allow.authenticated()` as the default. If guest access is required, scope it to read-only on non-sensitive models only.
238
+
200
239
To **disable** guest access, use a CDK override in `backend.ts`:
0 commit comments