Skip to content

Commit 0e7d09e

Browse files
authored
feat: add discussions on IAM authz; authz on custom operations (#8076)
1 parent 1f9b136 commit 0e7d09e

File tree

1 file changed

+41
-1
lines changed
  • src/pages/[platform]/build-a-backend/data/customize-authz

1 file changed

+41
-1
lines changed

src/pages/[platform]/build-a-backend/data/customize-authz/index.mdx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,49 @@ do {
256256

257257
</InlineFilter>
258258

259+
## IAM authorization
260+
261+
All Amplify Gen 2 projects enable IAM authorization for data access. This ensures that the Amplify console's [data manager](/[platform]/build-a-backend/data/manage-with-amplify-console/) will be able to access your API. It also allows you to authorize other administrative or machine-to-machine access using your own IAM policies. See the [AWS AppSync Developer Guide](https://docs.aws.amazon.com/appsync/latest/devguide/security_iam_service-with-iam.html) for details on how AWS AppSync works with IAM.
262+
263+
## Authorization on custom types
264+
265+
Authorization rules are only supported on data models (model-level and field-level) and custom operations (queries, mutations and subscriptions). They are not fully supported on custom types, including custom types returned by custom operations. For example, consider a custom query that returns a custom type:
266+
267+
```ts
268+
const schema = a.schema({
269+
Counter: a.customType({
270+
value: a.integer(),
271+
})
272+
.authorization(...), // <-- not supported
273+
getCounter: a
274+
.mutation()
275+
.arguments({
276+
id: a.string().required(),
277+
})
278+
.returns(a.ref("Counter"))
279+
.handler(
280+
a.handler.custom({
281+
entry: "./getCounter.js",
282+
})
283+
)
284+
.authorization((allow) => [allow.authenticated()]),
285+
});
286+
287+
export type Schema = ClientSchema<typeof schema>;
288+
289+
export const data = defineData({
290+
schema: schema,
291+
authorizationModes: {
292+
defaultAuthorizationMode: "userPool",
293+
},
294+
});
295+
```
296+
297+
As you can see, the custom `Counter` type does not support the `.authorization()` modifier. Instead, behind the scenes, Amplify will add appropriate authorization rules to `Counter` to allow authenticated users to access it. That means that any signed-in user will be able to access the custom operation and all fields of the custom type.
298+
259299
<Callout info>
260300

261-
**Note**: Authorization rules are only supported on data models (model-level and field-level) and custom operations (queries, mutations and subscriptions). They are not fully supported on custom types.
301+
**Note**: IAM authorization is not currently supported for custom operations that return custom types if `defaultAuthorizationMode` is not `iam`. See [GitHub issue #2929](https://github.com/aws-amplify/amplify-category-api/issues/2929) for details and suggested workarounds.
262302

263303
</Callout>
264304

0 commit comments

Comments
 (0)