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/auth/use-existing-cognito-resources/index.mdx
+12-98Lines changed: 12 additions & 98 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,113 +29,20 @@ export function getStaticProps(context) {
29
29
};
30
30
}
31
31
32
-
Amplify Auth can be configured to use an existing Amazon Cognito user pool and identity pool. If you are in a team setting or part of a company that has previously created auth resources, you have a few different options to configure your application to use existing auth resources.
33
-
34
-
If you are using Amplify to build your backend, it is recommended to [add a reference to your auth resource using `backend.addOutput`](#use-auth-resources-with-an-amplify-backend).
35
-
36
-
If you do not use Amplify to build your backend, you can [configure the client library directly](#use-auth-resources-without-an-amplify-backend).
32
+
Amplify Auth can be configured to use an existing Amazon Cognito user pool and identity pool. If you are in a team setting or part of a company that has previously created auth resources, you can [configure the client library directly](#use-auth-resources-without-an-amplify-backend), or maintain references with [AWS Cloud Development Kit (AWS CDK)](https://aws.amazon.com/cdk/) in your Amplify backend.
37
33
38
34
<Calloutinfo>
39
35
40
-
**Note:** when using existing auth resources, it may be necessary to add policies or permissions for your authenticated and unauthenticated IAM roles. These changes must be performed manually using the [AWS Cloud Development Kit (AWS CDK)](https://aws.amazon.com/cdk/)
41
-
42
-
</Callout>
43
-
44
-
## Use auth resources with an Amplify backend
45
-
46
-
The easiest way to get started with your existing resource is to use `backend.addOutput` to surface auth configuration to `amplify_outputs.json` automatically. In it's simplest form:
**Warning:** if you are creating an auth resource with `defineAuth`, you cannot override the default auth configuration automatically surfaced to `amplify_outputs.json` by Amplify.
36
+
**Note:** when using existing auth resources, it may be necessary to add additional policies or permissions for your authenticated and unauthenticated IAM roles. These changes must be performed manually.
80
37
81
38
</Callout>
82
39
83
-
You can also use the CDK to dynamically reference existing resources, and use metadata from that resource to set up IAM policies for other resources, or reference as an authorizer for a custom REST API:
You can use existing resources without an Amplify backend by configuring the client library directly.
45
+
139
46
```ts title="src/main.ts"
140
47
import { Amplify } from"aws-amplify"
141
48
@@ -178,7 +85,6 @@ Configuring the mobile client libraries directly is not supported, however you c
178
85
179
86
</Callout>
180
87
181
-
{/* pending hosted outputs schema */}
182
88
```json title="amplify_outputs.json"
183
89
{
184
90
"version": "1",
@@ -204,6 +110,14 @@ Configuring the mobile client libraries directly is not supported, however you c
204
110
205
111
</InlineFilter>
206
112
113
+
## Use auth resources with an Amplify backend
114
+
115
+
<Calloutwarning>
116
+
117
+
**Warning:** Amplify resources do not support including auth configurations by referencing with CDK. We are currently working to improve this experience by providing first-class support for referencing existing auth resources. [View the RFC for `referenceAuth` for more details](https://github.com/aws-amplify/amplify-backend/issues/1548)
118
+
119
+
</Callout>
120
+
207
121
## Next steps
208
122
209
123
-[Learn how to connect your frontend](/[platform]/build-a-backend/auth/connect-your-frontend/)
description: 'You can use Amplify client libraries to connect directly to your AWS resources',
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
+
exportasyncfunction getStaticPaths() {
21
+
returngetCustomStaticPath(meta.platforms);
22
+
}
23
+
24
+
exportfunction getStaticProps(context) {
25
+
return {
26
+
props: {
27
+
platform: context.params.platform,
28
+
meta
29
+
}
30
+
};
31
+
}
32
+
33
+
Amplify client libraries provide you with the flexibility to directly connect your application to AWS resources such as AWS AppSync, Amazon Cognito, Amazon S3, and more.
34
+
35
+
To get started, client libraries must be _configured_. This is typically done by using the [`amplify_outputs.json` file](/[platform]/reference/amplify_outputs) generated by the Amplify backend tooling, however using the client libraries does not require backend resources to be created by Amplify.
For JavaScript-based applications, the client library can be configured by using the generated outputs file:
40
+
41
+
```ts title="src/main.ts"
42
+
import { Amplify } from"aws-amplify"
43
+
importoutputsfrom"../amplify_outputs.json"
44
+
45
+
Amplify.configure(outputs)
46
+
```
47
+
48
+
Or by configuring the library directly by passing a [`ResourcesConfig`](https://aws-amplify.github.io/amplify-js/api/interfaces/aws_amplify.index.ResourcesConfig.html) object. For example, to configure the client library for use with Amazon Cognito, specify the `Auth` configuration:
By configuring the client library, Amplify automates the communication with the underlying AWS resources, and provides a friendly API to author your business logic. In the snippet below, the `signIn` function does not require passing information from your Cognito resource to initiate the sign-in flow.
For mobile platforms, the client library can be configured by creating an `amplify_outputs.json` file in your project's directory. To get started, create the file and specify your resource configuration:
0 commit comments