aws-amplify / docs

AWS Amplify Framework Documentation
https://docs.amplify.aws
Apache License 2.0
485 stars 1.05k forks source link

[Content Issue]: Looking for the schema/spec for amplifyconfiguration.json #6660

Open armenr opened 10 months ago

armenr commented 10 months ago

Describe the content issue: As a user, I'd like to know where I can find the amplifyconfiguration.json schema. In other words, it would be very helpful to know all of the possible key/value (and nested key/value) pairs that this file exposes to the Amplify.configure({}) function, by default.

After some digging: I was able to find this: https://github.com/aws-amplify/amplify-js/blob/a6a413caeec3570800168b8cc7cf976d7d765706/packages/core/src/parseAWSExports.ts#L33

It would appear this is where the magic happens, but this is a whole heck of a lot for a developer to go through, just to know what the config schema is for defining the config that the amplify library expects to consume, by default.

The existing documentation makes it impossible to infer the shape or schema of the JSON configuration file: https://docs.amplify.aws/vue/tools/libraries/configure-categories/

Use case

As an AWS Amplify user, I'd like to use CDK in place of the amplify cli-generated categories. I'd like to export and write my CDK outputs in an identical format to the amplifyconfiguration.json schema, so that configuration of my Amplify libraries is seamless/transparent to Amplify. Stated differently, I could just call Amplify.configure() without needing to manually configure each of the subcategories by pulling their values out of a custome-generated CDK output json file.

URL page where content issue is: Uncertain which page it would belong in.

Other Notes

GitHub Co-Pilot and I had a nice chat about this. See screenshot πŸ‘‡

Screenshot 2023-12-14 at 1 50 37β€―PM

I told it to consume amplify-js/packages/core/src/parseAWSExports.ts and reverse-engineer the JSON schema for the config file.

This is what I got back:

{
  "aws_project_region": "string",
  "aws_appsync_apiKey": "string",
  "aws_appsync_authenticationType": "string",
  "aws_appsync_graphqlEndpoint": "string",
  "aws_appsync_region": "string",
  "aws_bots_config": "array",
  "aws_cognito_identity_pool_id": "string",
  "aws_cognito_sign_up_verification_method": "string",
  "aws_cognito_mfa_configuration": "string",
  "aws_cognito_mfa_types": ["string"],
  "aws_cognito_password_protection_settings": {
    "passwordPolicyMinLength": "number",
    "passwordPolicyCharacters": ["string"]
  },
  "aws_cognito_verification_mechanisms": ["string"],
  "aws_cognito_signup_attributes": ["string"],
  "aws_cognito_social_providers": ["string"],
  "aws_cognito_username_attributes": ["string"],
  "aws_mandatory_sign_in": "string",
  "aws_mobile_analytics_app_id": "string",
  "aws_mobile_analytics_app_region": "string",
  "aws_user_files_s3_bucket": "string",
  "aws_user_files_s3_bucket_region": "string",
  "aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing": "boolean",
  "aws_user_pools_id": "string",
  "aws_user_pools_web_client_id": "string",
  "geo": {
    "amazon_location_service": {
      "search_indices": ["string"],
      "region": "string"
    }
  },
  "oauth": {
    "domain": "string",
    "scope": ["string"],
    "redirectSignIn": "string",
    "redirectSignOut": "string",
    "responseType": "string"
  },
  "predictions": {
    "convert": {
      "speechGenerator": {
        "defaults": {
          "VoiceId": "string"
        }
      }
    }
  },
  "aws_cloud_logic_custom": [
    {
      "name": "string",
      "endpoint": "string",
      "region": "string",
      "service": "string"
    }
  ],
  "Notifications": {
    "InAppMessaging": {
      "AWSPinpoint": {
        "appId": "string",
        "region": "string"
      }
    },
    "Push": {
      "AWSPinpoint": {
        "appId": "string",
        "region": "string"
      }
    }
  },
  "modelIntrospection": "boolean"
}
armenr commented 10 months ago

Was feeling a bit spicy, so I pushed Co-Pilot just a bit further. Here's what it produced (as an exmaple/sample).

It is worth noting that even in this case, it doesn't appear to fully cover or specify everything that's documented in categories and sub-configurations here: https://docs.amplify.aws/vue/tools/libraries/configure-categories/

Amplify Configuration Schema

General Configuration

Cognito Configuration

Mobile Analytics Configuration

User Files Configuration

Geo Configuration

OAuth Configuration

Predictions Configuration

Cloud Logic Configuration

Notifications Configuration

Model Introspection Configuration

nadetastic commented 10 months ago

Hi @armenr thanks for opening this issue. In the case where you are not relying on the auto generated amplifyconfiguration.json file, I'd recommend following the format for config depending on the category you need (Auth, API etc) and defined in the link you shared here - https://docs.amplify.aws/vue/tools/libraries/configure-categories/

Curious to understand what limitations you are facing with this approach?

armenr commented 10 months ago

Hey @nadetastic ! Thanks for diving into the issue with me, and for the prompt attention. :)

In terms of DX and productivity, our feeling is that it would be way more productive if we could just write out (to file) the CDK outputs to match the expected schema of the amplifyconfiguration.json file (and even "mock" or "impersonate" that file with our own CDK outputs) would be way more productive than writing out a file, and then doing something like πŸ‘‡ this, where we have to cherry-pick them one by one.

import cdkOutputs from '../outputs.json'

Amplify.configure({
    aws_appsync_graphqlEndpoint: cdkOutputs.BackendStack.AppSyncAPIURL,
    aws_appsync_region: cdkOutputs.BackendStack.awsAppsyncRegion,
    aws_appsync_authenticationType: cdkOutputs.BackendStack.AppSyncAuthType,
    aws_appsync_apiKey: cdkOutputs.BackendStack.AppSyncAPIKey,
})

That would be the use-case for the ask. Just saving the time of pulling these in and mapping them, one-by-one. If the ask is a bit of a stretch, or it's antithetical to the intended DX of Amplify, I'm happy to withdraw my request 😎