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
Copy file name to clipboardExpand all lines: src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx
+48-2Lines changed: 48 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ In your application, you can perform CRUD operations against the model by specif
79
79
try {
80
80
final todo = Todo(content: 'My new todo');
81
81
final request = ModelMutations.create(
82
-
todo,
82
+
todo,
83
83
authorizationMode: APIAuthorizationType.apiKey,
84
84
);
85
85
final createdTodo = await Amplify.API.mutations(request: request).response;
@@ -112,6 +112,52 @@ do {
112
112
113
113
</InlineFilter>
114
114
115
+
### Extend API Key Expiration
116
+
117
+
If the API key has not expired, you can extend the expiration date by deploying your app again. The API key expiration date will be set to `expiresInDays` days from the date when the app is deployed. In the example below, the API key will expire 7 days from the latest deployment.
118
+
119
+
```ts title="amplify/data/resource.ts"
120
+
exportconst data =defineData({
121
+
schema,
122
+
authorizationModes: {
123
+
defaultAuthorizationMode: 'apiKey',
124
+
apiKeyAuthorizationMode: {
125
+
expiresInDays: 7,
126
+
},
127
+
},
128
+
});
129
+
```
130
+
131
+
### Rotate an API Key
132
+
133
+
You can rotate an API key if it was expired, compromised, or deleted. To rotate an API key, you can override the logical ID of the API key resource in the `amplify/backend.ts` file. This will create a new API key with a new logical ID.
## Add public authorization rule using Amazon Cognito identity pool's unauthenticated role
116
162
117
163
You can also override the authorization provider. In the example below, `identityPool` is specified as the provider which allows you to use an "Unauthenticated Role" from the Cognito identity pool for public access instead of an API key. Your Auth resources defined in `amplify/auth/resource.ts` generates scoped down IAM policies for the "Unauthenticated role" in the Cognito identity pool automatically.
@@ -182,7 +228,7 @@ In your application, you can perform CRUD operations against the model with the
182
228
try {
183
229
final todo = Todo(content: 'My new todo');
184
230
final request = ModelMutations.create(
185
-
todo,
231
+
todo,
186
232
authorizationMode: APIAuthorizationType.iam,
187
233
);
188
234
final createdTodo = await Amplify.API.mutations(request: request).response;
0 commit comments