Page updated Nov 14, 2023

Use existing resources without the CLI

If you are using the Amplify CLI, an existing Amazon Cognito User Pool and Identity Pool can be used with the Amplify Libraries by running:

1amplify import auth

For more details, see how to Use an existing Cognito User Pool and Identity Pool.

If you are not using the Amplify CLI, a Cognito User Pool and Identity Pool can be used by referencing them in your amplifyconfiguration.dart file.

1const amplifyconfig = ''' {
2 "UserAgent": "aws-amplify-cli/2.0",
3 "Version": "1.0",
4 "auth": {
5 "plugins": {
6 "awsCognitoAuthPlugin": {
7 "IdentityManager": {
8 "Default": {}
9 },
10 "CredentialsProvider": {
11 "CognitoIdentity": {
12 "Default": {
13 "PoolId": "[COGNITO IDENTITY POOL ID]",
14 "Region": "[REGION]"
15 }
16 }
17 },
18 "CognitoUserPool": {
19 "Default": {
20 "PoolId": "[COGNITO USER POOL ID]",
21 "AppClientId": "[COGNITO USER POOL APP CLIENT ID]",
22 "Region": "[REGION]"
23 }
24 },
25 "Auth": {
26 "Default": {
27 "authenticationFlowType": "USER_SRP_AUTH",
28 "OAuth": {
29 "WebDomain": "[YOUR COGNITO DOMAIN ]",
30 "AppClientId": "[COGNITO USER POOL APP CLIENT ID]",
31 "SignInRedirectURI": "[CUSTOM REDIRECT SCHEME AFTER SIGN IN, e.g. myapp://]",
32 "SignOutRedirectURI": "[CUSTOM REDIRECT SCHEME AFTER SIGN OUT, e.g. myapp://]",
33 "Scopes": [
34 "phone",
35 "email",
36 "openid",
37 "profile",
38 "aws.cognito.signin.user.admin"
39 ]
40 }
41 }
42 }
43 }
44 }
45 }
46}''';
  • CredentialsProvider:
    • Cognito Identity:
      • Default:
        • PoolID: ID of the Amazon Cognito Identity Pool (e.g. us-east-1:123e4567-e89b-12d3-a456-426614174000)
        • Region: AWS Region where the resources are provisioned (e.g. us-east-1)
  • CognitoUserPool:
    • Default:
      • PoolId: ID of the Amazon Cognito User Pool (e.g. us-east-1_abcdefghi)
      • AppClientId: ID for the client used to authenticate against the user pool
      • Region: AWS Region where the resources are provisioned (e.g. us-east-1)
  • Auth:
    • Default:
      • authenticationFlowType: The authentication flow type, takes values USER_SRP_AUTH, CUSTOM_AUTH, and USER_PASSWORD_AUTH. Default is USER_SRP_AUTH.
      • OAuth: Hosted UI Configuration (only include this if using the Hosted UI flow)
        • Scopes: Scopes should match the scopes enables in Cognito under "App client settings"

Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see Install Amplify Libraries.

If you are using a Cognito User Pool without a Cognito Identity Pool, you can omit the CredentialsProvider section in the configuration.