From 6348dabf4f6a89f0bf9444b9008ba9c087fd7d41 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Wed, 19 Feb 2025 17:13:35 -0800 Subject: [PATCH 1/5] fix(js): gen1 recommend parseAmplifyConfig instead of calling configure twice --- .../lib/analytics/js/existing-resources.mdx | 8 ++++++-- src/fragments/lib/analytics/js/personalize.mdx | 4 +++- src/fragments/lib/analytics/js/storing.mdx | 4 +++- src/fragments/lib/analytics/js/streaming.mdx | 4 +++- src/fragments/lib/geo/js/existing-resources.mdx | 4 ++-- .../lib/interactions/js/getting-started.mdx | 8 ++++---- src/fragments/lib/restapi/js/existing-resources.mdx | 13 +++++++++---- .../lib/troubleshooting/common/upgrading.mdx | 7 +++---- .../analytics/streaming-data/index.mdx | 1 + .../predictions/set-up-predictions/index.mdx | 10 ++++++++-- .../restapi/existing-resources/index.mdx | 10 +++++----- .../storage/existing-resources/index.mdx | 6 +++--- 12 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/fragments/lib/analytics/js/existing-resources.mdx b/src/fragments/lib/analytics/js/existing-resources.mdx index c0d7c4d5655..fb46edc1e58 100644 --- a/src/fragments/lib/analytics/js/existing-resources.mdx +++ b/src/fragments/lib/analytics/js/existing-resources.mdx @@ -4,11 +4,15 @@ The manual setup enables you to use your existing Amazon Pinpoint resource in yo ```javascript import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; +import amplifyconfig from './amplifyconfiguration.json'; + +const resourceConfig = parseAmplifyConfig(amplifyconfig); Amplify.configure({ - ...Amplify.getConfig(), + ...resourceConfig, Analytics: { - ...Amplify.getConfig().Analytics, + ...resourceConfig.Analytics, Pinpoint: { // REQUIRED - Amazon Pinpoint App Client ID appId: 'XXXXXXXXXXabcdefghij1234567890ab', diff --git a/src/fragments/lib/analytics/js/personalize.mdx b/src/fragments/lib/analytics/js/personalize.mdx index 247ad480e41..e3f4ffcc304 100644 --- a/src/fragments/lib/analytics/js/personalize.mdx +++ b/src/fragments/lib/analytics/js/personalize.mdx @@ -29,9 +29,11 @@ Configure Amazon Personalize: ```javascript import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; +import amplifyconfig from './amplifyconfiguration.json'; Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(amplifyconfig), Analytics: { Personalize: { // REQUIRED - The trackingId to track the events diff --git a/src/fragments/lib/analytics/js/storing.mdx b/src/fragments/lib/analytics/js/storing.mdx index 9ff5bb23d76..106a6f3a6fd 100644 --- a/src/fragments/lib/analytics/js/storing.mdx +++ b/src/fragments/lib/analytics/js/storing.mdx @@ -22,9 +22,11 @@ Configure Kinesis Firehose: ```javascript import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; +import amplifyconfig from './amplifyconfiguration.json'; Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(amplifyconfig), Analytics: { KinesisFirehose: { // REQUIRED - Amazon Kinesis Firehose service region diff --git a/src/fragments/lib/analytics/js/streaming.mdx b/src/fragments/lib/analytics/js/streaming.mdx index 38b5bfb229c..a17e4fee463 100644 --- a/src/fragments/lib/analytics/js/streaming.mdx +++ b/src/fragments/lib/analytics/js/streaming.mdx @@ -24,9 +24,11 @@ Configure Kinesis: ```javascript // Configure the plugin after adding it to the Analytics module import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; +import amplifyconfig from './amplifyconfiguration.json'; Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(amplifyconfig), Analytics: { Kinesis: { // REQUIRED - Amazon Kinesis service region diff --git a/src/fragments/lib/geo/js/existing-resources.mdx b/src/fragments/lib/geo/js/existing-resources.mdx index aecf600cf5a..5b3277ae804 100644 --- a/src/fragments/lib/geo/js/existing-resources.mdx +++ b/src/fragments/lib/geo/js/existing-resources.mdx @@ -4,11 +4,11 @@ You can first import and configure the CLI generated `amplifyconfiguration.json` ```js import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; import amplifyconfig from './amplifyconfiguration.json'; -Amplify.configure(amplifyconfig); Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(amplifyconfig), Geo: { LocationService: { maps: { diff --git a/src/fragments/lib/interactions/js/getting-started.mdx b/src/fragments/lib/interactions/js/getting-started.mdx index cffb904c9e3..41267131fbe 100644 --- a/src/fragments/lib/interactions/js/getting-started.mdx +++ b/src/fragments/lib/interactions/js/getting-started.mdx @@ -35,11 +35,11 @@ For adding IAM permissions, find you IAM role and attach the policy below (_reme ```javascript import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; import amplifyconfig from './amplifyconfiguration.json'; -Amplify.configure(amplifyconfig); Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(amplifyconfig), Interactions: { LexV2: { '': { @@ -125,11 +125,11 @@ Configuring bot details in your web app like this: ```javascript import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; import amplifyconfig from './amplifyconfiguration.json'; -Amplify.configure(amplifyconfig); Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(amplifyconfig), Interactions: { LexV1: { '': { diff --git a/src/fragments/lib/restapi/js/existing-resources.mdx b/src/fragments/lib/restapi/js/existing-resources.mdx index ba7baa601a4..e844f84e01c 100644 --- a/src/fragments/lib/restapi/js/existing-resources.mdx +++ b/src/fragments/lib/restapi/js/existing-resources.mdx @@ -1,13 +1,18 @@ Existing Amazon API Gateway resources can be used with the Amplify Libraries by calling `Amplify.configure()` with the API Gateway API name and options. Note you need to supply the full resource configuration and library options objects when calling `Amplify.configure()`. The following example shows how to configure additional API Gateway resources to an existing Amplify application: ```javascript -const existingConfig = Amplify.getConfig(); +import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; +import amplifyconfig from './amplifyconfiguration.json'; + +const resourceConfig = parseAmplifyConfig(amplifyconfig); + Amplify.configure({ - ...existingConfig, + ...resourceConfig, API: { - ...existingConfig.API, + ...resourceConfig.API, REST: { - ...existingConfig.API?.REST, + ...resourceConfig.API?.REST, '[API NAME]': { endpoint: '[API GATEWAY ENDPOINT]', region: '[REGION]' diff --git a/src/fragments/lib/troubleshooting/common/upgrading.mdx b/src/fragments/lib/troubleshooting/common/upgrading.mdx index f92221c2b57..ed2b0fa9011 100644 --- a/src/fragments/lib/troubleshooting/common/upgrading.mdx +++ b/src/fragments/lib/troubleshooting/common/upgrading.mdx @@ -177,7 +177,7 @@ Wherever you called `Amplify.configure({ aws-exports });` previously (usually in - `Amplify.configure()` will now accept either the config JSON file or a strongly typed configuration object. Therefore, if you need to add additional configuration, you will call configure twice: once with the contents of **amplifyconfiguration.json**, and then again using `Amplify.getConfig()` plus any additions. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. + `Amplify.configure()` will now accept either the config JSON file or a strongly typed configuration object. You can use the `parseAmplifyConfig` util to parse the contents of config JSON file **amplifyconfiguration.json** into the strongly typed configuration object and modify or override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. If you have previously configured Amplify by passing the configuration object literal when calling the `Amplify.configure()` function, you can now configure Amplify manually with type safety. Please refer to the documentation of each category that you are using for migration. @@ -635,10 +635,9 @@ In v6, the `AWSLexV2Provider` provider will be included by default and you are n ``` import { Amplify } from 'aws-amplify'; + import { parseAmplifyConfig } from "aws-amplify/utils"; import amplifyconfig from './amplifyconfiguration.json'; - Amplify.configure(amplifyconfig); - const interactionsConfig = { LexV2: { '': { @@ -651,7 +650,7 @@ In v6, the `AWSLexV2Provider` provider will be included by default and you are n } Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(amplifyconfig), Interactions: interactionsConfig }); ``` diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/streaming-data/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/streaming-data/index.mdx index 2ded8bd5ad4..8bd5f4d32ee 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/streaming-data/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/streaming-data/index.mdx @@ -93,6 +93,7 @@ Configure Kinesis: ```javascript title="src/index.js" // Configure the plugin after adding it to the Analytics module import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; import outputs from '../amplify_outputs.json'; const amplifyConfig = parseAmplifyConfig(outputs); diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/predictions/set-up-predictions/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/predictions/set-up-predictions/index.mdx index 25b37e8b083..a5e270adabe 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/predictions/set-up-predictions/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/predictions/set-up-predictions/index.mdx @@ -154,7 +154,13 @@ Import and load the configuration file in your app. It is recommended you add th ```ts title="src/main.ts" import { Amplify } from "aws-amplify"; -import outputs from '../amplify_outputs.json'; +import { parseAmplifyConfig } from "aws-amplify/utils"; +import outputs from './amplify_outputs.json'; -Amplify.configure(outputs); +const amplifyConfig = parseAmplifyConfig(outputs); + +Amplify.configure({ + ...amplifyConfig, + Predictions: outputs.custom.Predictions, +}); ``` diff --git a/src/pages/gen1/[platform]/build-a-backend/restapi/existing-resources/index.mdx b/src/pages/gen1/[platform]/build-a-backend/restapi/existing-resources/index.mdx index 9c03706ff6d..75b3a4bc86b 100644 --- a/src/pages/gen1/[platform]/build-a-backend/restapi/existing-resources/index.mdx +++ b/src/pages/gen1/[platform]/build-a-backend/restapi/existing-resources/index.mdx @@ -47,18 +47,18 @@ Existing Amazon API Gateway resources can be used with the Amplify Libraries by ```javascript import { Amplify } from 'aws-amplify'; +import { parseAmplifyConfig } from "aws-amplify/utils"; import amplifyconfig from './src/amplifyconfiguration.json'; -Amplify.configure(amplifyconfig): -const existingConfig = Amplify.getConfig(); +const resourceConfig = parseAmplifyConfig(amplifyconfig); // Add existing resource to the existing configuration. Amplify.configure({ - ...existingConfig, + ...resourceConfig, API: { - ...existingConfig.API, + ...resourceConfig.API, REST: { - ...existingConfig.API?.REST, + ...resourceConfig.API?.REST, YourAPIName: { endpoint: 'https://abcdefghij1234567890.execute-api.us-east-1.amazonaws.com/stageName', diff --git a/src/pages/gen1/[platform]/build-a-backend/storage/existing-resources/index.mdx b/src/pages/gen1/[platform]/build-a-backend/storage/existing-resources/index.mdx index 2b77352ce4f..afa6f55b307 100644 --- a/src/pages/gen1/[platform]/build-a-backend/storage/existing-resources/index.mdx +++ b/src/pages/gen1/[platform]/build-a-backend/storage/existing-resources/index.mdx @@ -59,11 +59,11 @@ If you are not using the Amplify CLI, an existing Amazon S3 bucket can be used b ```javascript import { Amplify } from 'aws-amplify'; -import amplifyconfig from './amplifyconfiguration.json'; +import { parseAmplifyConfig } from "aws-amplify/utils"; +import resourceConfig from './amplifyconfiguration.json'; -Amplify.configure(amplifyconfig); Amplify.configure({ - ...Amplify.getConfig(), + ...parseAmplifyConfig(resourceConfig), Storage: { S3: { region: '[REGION]', // (required) - Amazon S3 bucket region From 3dab0739ac8e4b8718acfd1365c6e24fd2279666 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Thu, 20 Feb 2025 12:58:23 -0800 Subject: [PATCH 2/5] address feedback --- src/fragments/lib/troubleshooting/common/upgrading.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/troubleshooting/common/upgrading.mdx b/src/fragments/lib/troubleshooting/common/upgrading.mdx index ed2b0fa9011..71b639c07af 100644 --- a/src/fragments/lib/troubleshooting/common/upgrading.mdx +++ b/src/fragments/lib/troubleshooting/common/upgrading.mdx @@ -177,7 +177,7 @@ Wherever you called `Amplify.configure({ aws-exports });` previously (usually in - `Amplify.configure()` will now accept either the config JSON file or a strongly typed configuration object. You can use the `parseAmplifyConfig` util to parse the contents of config JSON file **amplifyconfiguration.json** into the strongly typed configuration object and modify or override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. + `Amplify.configure()` will now accept either the config JSON file or a typed configuration object. You can use the `parseAmplifyConfig` util to parse the contents of config JSON file **amplifyconfiguration.json** into the typed configuration object and override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. If you have previously configured Amplify by passing the configuration object literal when calling the `Amplify.configure()` function, you can now configure Amplify manually with type safety. Please refer to the documentation of each category that you are using for migration. From 08855c1d7c26c66cf07190a78e012086c4721c4d Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Thu, 20 Feb 2025 13:23:57 -0800 Subject: [PATCH 3/5] address feedback --- src/fragments/lib/troubleshooting/common/upgrading.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/troubleshooting/common/upgrading.mdx b/src/fragments/lib/troubleshooting/common/upgrading.mdx index 71b639c07af..3d066ada4da 100644 --- a/src/fragments/lib/troubleshooting/common/upgrading.mdx +++ b/src/fragments/lib/troubleshooting/common/upgrading.mdx @@ -177,7 +177,7 @@ Wherever you called `Amplify.configure({ aws-exports });` previously (usually in - `Amplify.configure()` will now accept either the config JSON file or a typed configuration object. You can use the `parseAmplifyConfig` util to parse the contents of config JSON file **amplifyconfiguration.json** into the typed configuration object and override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. + `Amplify.configure()` accepts either the config JSON file or a ResourceConfig configuration object. You can use the `parseAmplifyConfig` util to parse the contents of the config JSON file **amplifyconfiguration.json** into the ResourceConfig configuration object and override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. If you have previously configured Amplify by passing the configuration object literal when calling the `Amplify.configure()` function, you can now configure Amplify manually with type safety. Please refer to the documentation of each category that you are using for migration. From 2b277edd19bbcfe06c142822e936df5a8ecec477 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Thu, 20 Feb 2025 13:31:36 -0800 Subject: [PATCH 4/5] Update src/fragments/lib/troubleshooting/common/upgrading.mdx Co-authored-by: Caleb Pollman --- src/fragments/lib/troubleshooting/common/upgrading.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/troubleshooting/common/upgrading.mdx b/src/fragments/lib/troubleshooting/common/upgrading.mdx index 3d066ada4da..ab62d1d922b 100644 --- a/src/fragments/lib/troubleshooting/common/upgrading.mdx +++ b/src/fragments/lib/troubleshooting/common/upgrading.mdx @@ -177,7 +177,7 @@ Wherever you called `Amplify.configure({ aws-exports });` previously (usually in - `Amplify.configure()` accepts either the config JSON file or a ResourceConfig configuration object. You can use the `parseAmplifyConfig` util to parse the contents of the config JSON file **amplifyconfiguration.json** into the ResourceConfig configuration object and override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. + `Amplify.configure()` accepts either the config JSON file or a `ResourcesConfig` configuration object. You can use the `parseAmplifyConfig` util to parse the contents of the config JSON file **amplifyconfiguration.json** into the `ResourcesConfig` configuration object and override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. If you have previously configured Amplify by passing the configuration object literal when calling the `Amplify.configure()` function, you can now configure Amplify manually with type safety. Please refer to the documentation of each category that you are using for migration. From bf6ce302ea61904289a0a000b79ab9a517533b88 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Mon, 3 Mar 2025 17:05:37 -0800 Subject: [PATCH 5/5] add reference link for resourcesConfig --- src/fragments/lib/troubleshooting/common/upgrading.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragments/lib/troubleshooting/common/upgrading.mdx b/src/fragments/lib/troubleshooting/common/upgrading.mdx index ab62d1d922b..f6001064506 100644 --- a/src/fragments/lib/troubleshooting/common/upgrading.mdx +++ b/src/fragments/lib/troubleshooting/common/upgrading.mdx @@ -177,7 +177,7 @@ Wherever you called `Amplify.configure({ aws-exports });` previously (usually in - `Amplify.configure()` accepts either the config JSON file or a `ResourcesConfig` configuration object. You can use the `parseAmplifyConfig` util to parse the contents of the config JSON file **amplifyconfiguration.json** into the `ResourcesConfig` configuration object and override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. + `Amplify.configure()` accepts either the config JSON file or a [ResourceConfig configuration object](/gen1/[platform]/tools/libraries/configure-categories/). You can use the `parseAmplifyConfig` util to parse the contents of the config JSON file **amplifyconfiguration.json** into the ResourceConfig configuration object and override properties as needed. Keep in mind that any call to configuration will fully override previous configurations, so pay special attention to nested configurations. If you have previously configured Amplify by passing the configuration object literal when calling the `Amplify.configure()` function, you can now configure Amplify manually with type safety. Please refer to the documentation of each category that you are using for migration.