What options can I pass to Amplify.configure()?
Asked Answered
S

2

13

There seem to be two different ways to configure Amplify. Some examples use a key-value properties format:

import aws_exports from "./aws-exports";
Amplify.configure(aws_exports);

Where the aws-exports is something like this:

    const awsmobile = {
        "aws_project_region": "ap-southeast-2",
        "aws_appsync_graphqlEndpoint": "<my graphQL endpoint URL>",
        "aws_appsync_region": "ap-southeast-2",
        "aws_appsync_authenticationType": "API_KEY",
        "aws_appsync_apiKey": "<my API key>",
        "aws_cognito_region": "ap-southeast-2",
        "aws_user_pools_id": "<my user pool id>",
        "aws_user_pools_web_client_id": "<my user pool web client id>",
        "aws_cognito_identity_pool_id": "<my cognito id pool id>",
    };
    export default awsmobile;

And other examples configure Amplify (and its modules) passing the properties in a json format:

Amplify.configure({
  Auth: {
    mandatorySignIn: true,
    region: "ap-southeast-2",
    userPoolId: "<my user pool id>",
    identityPoolId: "<my cognito id pool id>",
    userPoolWebClientId: "<my user pool web client id>"
  },
});

The properties are similar but different. I currently use the key-value properties but want to reconfigure Appsync to use authenticationType AMAZON_COGNITO_USER_POOLS using the json format.

What is the difference in the two formats and how do the key-values translate to the Json structure?

Syncarpous answered 23/3, 2021 at 10:42 Comment(0)
S
6

Revisiting this question now, I found the differences between the general top-level and scoped configuration have been documented now in the Amplify Dev Center docs - including the different config categories (Auth, Storage, API).

See here https://docs.amplify.aws/lib/client-configuration/configuring-amplify-categories/q/platform/js/

Syncarpous answered 16/3, 2023 at 1:26 Comment(0)
T
7

I haven't come across any explicit explanation for the two formats. But if you look at the documentation page for setting up the Amplify API, the two formats are used in different scenarios. The automated setup uses the key-value file generated by the Amplify CLI (by importing "./aws-exports"). The manual setup, on the other hand, uses the nested json format.

The documentation makes similar differentiation for setting up Authentication, Analytics, etc. I believe the implication is that "./aws-exports" is a file generated by the Amplify CLI, so it shouldn't be modified manually and thus its key-value format is intended more for internal use. Examples for manual configuration tend to use the nested json format.

Having said that, the documentation is not 100% consistent. The documentation for Amplify GraphQL illustrates configuration using the key-value format when you're using AWS AppSync as your GraphQL server. To configure for other kinds of GraphQL servers, it uses the nested json format.

My best guess is that the Amplify library was originally designed to be self-contained and its key-value configuration file was only for internal use. Over time they opened it up for customization, and then created the nested json format to make configuration more readable (and possibly add type checking). However, things haven't fully switched over so we are seeing both formats in use.

Tiros answered 29/4, 2021 at 6:26 Comment(2)
I think you're right. Feels like technical debt that has not been addressed - neither in code nor documentation.Syncarpous
Seems that the key-value format is not supported anymore, starting from version 6.0.7 of the js library. Throwing an "Invalid config parameter" error that disappeared after I switched to the json format.Bigmouth
S
6

Revisiting this question now, I found the differences between the general top-level and scoped configuration have been documented now in the Amplify Dev Center docs - including the different config categories (Auth, Storage, API).

See here https://docs.amplify.aws/lib/client-configuration/configuring-amplify-categories/q/platform/js/

Syncarpous answered 16/3, 2023 at 1:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.