Skip to content

Commit 67bacb8

Browse files
committed
Merge branch 'add-migration-docs' into add-gen1-gen2-migrations
2 parents 8371448 + 1d5f59d commit 67bacb8

File tree

20 files changed

+937
-75
lines changed

20 files changed

+937
-75
lines changed

.github/workflows/accessibility_scan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env:
88
jobs:
99
accessibility:
1010
name: Runs accessibility scan on changed pages
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
steps:
1313
- name: Checkout branch
1414
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
@@ -32,7 +32,7 @@ jobs:
3232
const buildDir = process.env.BUILD_DIR;
3333
return getChangedPages({github, context, buildDir});
3434
- name: Run site
35-
run: |
35+
run: |
3636
python -m http.server 3000 -d ${{ env.BUILD_DIR }} &
3737
sleep 5
3838
- name: Run accessibility tests on changed/new MDX pages

.github/workflows/check_for_console_errors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions:
99
contents: read
1010
jobs:
1111
CheckConsoleErrors:
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313
steps:
1414
- name: Checkout repository
1515
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

.github/workflows/check_pr_for_broken_links.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env:
77
BUILD_DIR: 'client/www/next-build'
88
jobs:
99
CheckPRLinks:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- name: Checkout repository
1313
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"amazonaws",
6969
"amazonaws",
7070
"amazoncognito",
71+
"amazonlinux",
7172
"AmazonPersonalizeProvider",
7273
"AmazonS3Client",
7374
"Amplif",
@@ -494,6 +495,7 @@
494495
"dataaccess",
495496
"dataacess",
496497
"databinding",
498+
"datalogconfig",
497499
"dataset",
498500
"datasource",
499501
"DataSource",

src/directory/directory.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ export const directory = {
292292
},
293293
{
294294
path: 'src/pages/[platform]/build-a-backend/data/custom-business-logic/connect-http-datasource/index.mdx'
295+
},
296+
{
297+
path: 'src/pages/[platform]/build-a-backend/data/custom-business-logic/batch-ddb-operations/index.mdx'
295298
}
296299
]
297300
},
@@ -337,6 +340,9 @@ export const directory = {
337340
},
338341
{
339342
path: 'src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx'
343+
},
344+
{
345+
path: 'src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx'
340346
}
341347
]
342348
},

src/pages/[platform]/build-a-backend/auth/concepts/passwordless/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Passwordless authentication removes the security risks and user friction associa
4242

4343
</Callout>
4444

45+
Learn how to implement passwordless sign-in flows by [overriding the Cognito UserPool to enable the sign-in methods below](/[platform]/build-a-backend/auth/modify-resources-with-cdk/#override-cognito-userpool-to-enable-passwordless-sign-in-methods).
46+
4547
{/* need a section about what a "preferred" factor is */}
4648

4749
## SMS OTP

src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/index.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,12 @@ func confirmSignIn() -> AnyCancellable {
812812

813813
To sign in using an external identity provider such as Google, use the `signInWithRedirect` function.
814814

815+
<Callout info>
816+
817+
For guidance on configuring an external Identity Provider with Amplify see [External Identity Providers](/[platform]/build-a-backend/auth/concepts/external-identity-providers/)
818+
819+
</Callout>
820+
815821
```ts
816822
import { signInWithRedirect } from "aws-amplify/auth"
817823

src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@ You can alternatively download the introspection schema using the [`fetch-schema
320320
2. On the left side, select Schema
321321
3. When viewing your schema, there should a “Export schema” drop down. Select this and download the `schema.json` file.
322322
4. Add this file to your project as directed by [Apollo documentation](https://www.apollographql.com/docs/kotlin/advanced/plugin-recipes#specifying-the-schema-location)
323+
324+
### Type Mapping AppSync Scalars
325+
By default, [AWS AppSync Scalars](https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html#graph-ql-aws-appsync-scalars) will default to the `Any` type. You can map these scalars to more explicit types by editing the `apollo` block in your `app/build.gradle[.kts]` file. In the example below, we are now mapping a few of our AppSync scalar types to `String` instead of `Any`. Additional improvements could be made by writing [custom class adapters](https://www.apollographql.com/docs/kotlin/essentials/custom-scalars#define-class-mapping) to convert date/time scalars into Kotlin date/time class types.
326+
327+
```kotlin
328+
apollo {
329+
service("{serviceName}") {
330+
packageName.set("{packageName}")
331+
mapScalarToKotlinString("AWSDateTime")
332+
mapScalarToKotlinString("AWSEmail")
333+
}
334+
}
335+
```
323336
</InlineFilter>
324337

325338
### Performing Queries, Mutations, and Subscriptions with Apollo client

src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ When deploying your app to production, you need to [add the database connection
208208

209209
## Rename generated models and fields
210210

211-
To improve the ergonomics of your API, you might want to rename the generate fields or types to better accommodate your use case. Use the `renameModels()` and `renameModelFields()` modifiers to rename the auto-inferred data models and their fields.
211+
To improve the ergonomics of your API, you might want to rename the generate fields or types to better accommodate your use case. Use the `renameModels()` modifier to rename the auto-inferred data models.
212212

213213
```ts
214214
// Rename models or fields to be more idiomatic for frontend code
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Batch DynamoDB Operations',
5+
description:
6+
'Batch DynamoDB Operations',
7+
platforms: [
8+
'android',
9+
'angular',
10+
'flutter',
11+
'javascript',
12+
'nextjs',
13+
'react',
14+
'react-native',
15+
'swift',
16+
'vue'
17+
]
18+
};
19+
20+
export const getStaticPaths = async () => {
21+
return getCustomStaticPath(meta.platforms);
22+
};
23+
24+
export function getStaticProps() {
25+
return {
26+
props: {
27+
meta
28+
}
29+
};
30+
}
31+
32+
Batch DynamoDB operations allow you to add multiple items in single mutation.
33+
34+
## Step 1 - Define a custom mutation
35+
36+
```ts title="amplify/data/resource.ts"
37+
import { type ClientSchema, a, defineData } from '@aws-amplify/backend';
38+
39+
const schema = a.schema({
40+
// 1. Define your return type as a custom type or model
41+
Post: a.model({
42+
id: a.id(),
43+
content: a.string(),
44+
likes: a.integer()
45+
}),
46+
47+
// 2. Define your mutation with the return type and, optionally, arguments
48+
BatchCreatePost: a
49+
.mutation()
50+
// arguments that this query accepts
51+
.arguments({
52+
content: a.string().array()
53+
})
54+
.returns(a.ref('Post').array())
55+
// only allow signed-in users to call this API
56+
.authorization(allow => [allow.authenticated()])
57+
});
58+
59+
export type Schema = ClientSchema<typeof schema>;
60+
61+
export const data = defineData({
62+
schema
63+
});
64+
```
65+
66+
## Step 2 - Configure custom business logic handler code
67+
68+
After your query or mutation is defined, you need to author your custom business logic using a [custom resolver powered by AppSync JavaScript resolver](https://docs.aws.amazon.com/appsync/latest/devguide/tutorials-js.html).
69+
70+
Custom resolvers work on a "request/response" basis. You choose a data source, map your request to the data source's input parameters, and then map the data source's response back to the query/mutation's return type. Custom resolvers provide the benefit of no cold starts, less infrastructure to manage, and no additional charge for Lambda function invocations. Review [Choosing between custom resolver and function](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html#choosing-data-source).
71+
72+
In your `amplify/data/resource.ts` file, define a custom handler using `a.handler.custom`.
73+
74+
```ts title="amplify/data/resource.ts"
75+
import { type ClientSchema, a, defineData } from '@aws-amplify/backend';
76+
77+
const schema = a.schema({
78+
Post: a.model({
79+
id: a.id(),
80+
content: a.string(),
81+
likes: a.integer()
82+
}),
83+
84+
BatchCreatePost: a
85+
.mutation()
86+
.arguments({
87+
contents: a.string().array()
88+
})
89+
.returns(a.ref('Post').array())
90+
.authorization(allow => [allow.authenticated()])
91+
// 1. Add the custom handler
92+
.handler(
93+
a.handler.custom({
94+
dataSource: a.ref('Post'),
95+
entry: './BatchCreatePostHandler.js',
96+
})
97+
)
98+
});
99+
100+
export type Schema = ClientSchema<typeof schema>;
101+
102+
export const data = defineData({
103+
schema
104+
});
105+
```
106+
107+
Amplify will store some values in the resolver context stash that can be accessed in the custom resolver.
108+
109+
| Name | Description |
110+
| ------------------------- | -------------------------------------------- |
111+
| awsAppsyncApiId | The ID of the AppSync API. |
112+
| amplifyApiEnvironmentName | The Amplify api environment name. (`NONE` in sandbox) |
113+
114+
The Amplify generated DynamoDB table names can be constructed from the variables in the context stash. The table name is in the format `<model-name>-<aws-appsync-api-id>-<amplify-api-environment-name>`. For example, the table name for the `Post` model would be `Post-123456-dev` where `123456` is the AppSync API ID and `dev` is the Amplify API environment name.
115+
116+
```ts title="amplify/data/BatchCreatePostHandler.js"
117+
import { util } from '@aws-appsync/utils';
118+
119+
export function request(ctx) {
120+
var now = util.time.nowISO8601();
121+
122+
return {
123+
operation: 'BatchPutItem',
124+
tables: {
125+
[`Post-${ctx.stash.awsAppsyncApiId}-${ctx.stash.amplifyApiEnvironmentName}`]: ctx.args.contents.map((content) =>
126+
util.dynamodb.toMapValues({
127+
content,
128+
id: util.autoId(),
129+
createdAt: now,
130+
updatedAt: now,
131+
})
132+
),
133+
},
134+
};
135+
}
136+
137+
export function response(ctx) {
138+
if (ctx.error) {
139+
util.error(ctx.error.message, ctx.error.type);
140+
}
141+
return ctx.result.data[`Post-${ctx.stash.awsAppsyncApiId}-${ctx.stash.amplifyApiEnvironmentName}`];
142+
}
143+
```
144+
145+
## Step 3 - Invoke the custom query or mutation
146+
147+
From your generated Data client, you can find all your custom queries and mutations under the `client.queries.` and `client.mutations.` APIs respectively.
148+
149+
```ts
150+
const { data, errors } = await client.mutations.BatchCreatePost({
151+
contents: ['Post 1', 'Post 2', 'Post 3']
152+
});
153+
```

0 commit comments

Comments
 (0)