Skip to content

Commit 6348dab

Browse files
author
Ashwin Kumar
committed
fix(js): gen1 recommend parseAmplifyConfig instead of calling configure twice
1 parent 3d02111 commit 6348dab

File tree

12 files changed

+50
-29
lines changed

12 files changed

+50
-29
lines changed

src/fragments/lib/analytics/js/existing-resources.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ The manual setup enables you to use your existing Amazon Pinpoint resource in yo
44

55
```javascript
66
import { Amplify } from 'aws-amplify';
7+
import { parseAmplifyConfig } from "aws-amplify/utils";
8+
import amplifyconfig from './amplifyconfiguration.json';
9+
10+
const resourceConfig = parseAmplifyConfig(amplifyconfig);
711

812
Amplify.configure({
9-
...Amplify.getConfig(),
13+
...resourceConfig,
1014
Analytics: {
11-
...Amplify.getConfig().Analytics,
15+
...resourceConfig.Analytics,
1216
Pinpoint: {
1317
// REQUIRED - Amazon Pinpoint App Client ID
1418
appId: 'XXXXXXXXXXabcdefghij1234567890ab',

src/fragments/lib/analytics/js/personalize.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ Configure Amazon Personalize:
2929

3030
```javascript
3131
import { Amplify } from 'aws-amplify';
32+
import { parseAmplifyConfig } from "aws-amplify/utils";
33+
import amplifyconfig from './amplifyconfiguration.json';
3234

3335
Amplify.configure({
34-
...Amplify.getConfig(),
36+
...parseAmplifyConfig(amplifyconfig),
3537
Analytics: {
3638
Personalize: {
3739
// REQUIRED - The trackingId to track the events

src/fragments/lib/analytics/js/storing.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ Configure Kinesis Firehose:
2222

2323
```javascript
2424
import { Amplify } from 'aws-amplify';
25+
import { parseAmplifyConfig } from "aws-amplify/utils";
26+
import amplifyconfig from './amplifyconfiguration.json';
2527

2628
Amplify.configure({
27-
...Amplify.getConfig(),
29+
...parseAmplifyConfig(amplifyconfig),
2830
Analytics: {
2931
KinesisFirehose: {
3032
// REQUIRED - Amazon Kinesis Firehose service region

src/fragments/lib/analytics/js/streaming.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ Configure Kinesis:
2424
```javascript
2525
// Configure the plugin after adding it to the Analytics module
2626
import { Amplify } from 'aws-amplify';
27+
import { parseAmplifyConfig } from "aws-amplify/utils";
28+
import amplifyconfig from './amplifyconfiguration.json';
2729

2830
Amplify.configure({
29-
...Amplify.getConfig(),
31+
...parseAmplifyConfig(amplifyconfig),
3032
Analytics: {
3133
Kinesis: {
3234
// REQUIRED - Amazon Kinesis service region

src/fragments/lib/geo/js/existing-resources.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ You can first import and configure the CLI generated `amplifyconfiguration.json`
44

55
```js
66
import { Amplify } from 'aws-amplify';
7+
import { parseAmplifyConfig } from "aws-amplify/utils";
78
import amplifyconfig from './amplifyconfiguration.json';
89

9-
Amplify.configure(amplifyconfig);
1010
Amplify.configure({
11-
...Amplify.getConfig(),
11+
...parseAmplifyConfig(amplifyconfig),
1212
Geo: {
1313
LocationService: {
1414
maps: {

src/fragments/lib/interactions/js/getting-started.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ For adding IAM permissions, find you IAM role and attach the policy below (_reme
3535

3636
```javascript
3737
import { Amplify } from 'aws-amplify';
38+
import { parseAmplifyConfig } from "aws-amplify/utils";
3839
import amplifyconfig from './amplifyconfiguration.json';
3940

40-
Amplify.configure(amplifyconfig);
4141
Amplify.configure({
42-
...Amplify.getConfig(),
42+
...parseAmplifyConfig(amplifyconfig),
4343
Interactions: {
4444
LexV2: {
4545
'<V2BotName>': {
@@ -125,11 +125,11 @@ Configuring bot details in your web app like this:
125125

126126
```javascript
127127
import { Amplify } from 'aws-amplify';
128+
import { parseAmplifyConfig } from "aws-amplify/utils";
128129
import amplifyconfig from './amplifyconfiguration.json';
129130

130-
Amplify.configure(amplifyconfig);
131131
Amplify.configure({
132-
...Amplify.getConfig(),
132+
...parseAmplifyConfig(amplifyconfig),
133133
Interactions: {
134134
LexV1: {
135135
'<V1BotName>': {

src/fragments/lib/restapi/js/existing-resources.mdx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
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:
22

33
```javascript
4-
const existingConfig = Amplify.getConfig();
4+
import { Amplify } from 'aws-amplify';
5+
import { parseAmplifyConfig } from "aws-amplify/utils";
6+
import amplifyconfig from './amplifyconfiguration.json';
7+
8+
const resourceConfig = parseAmplifyConfig(amplifyconfig);
9+
510
Amplify.configure({
6-
...existingConfig,
11+
...resourceConfig,
712
API: {
8-
...existingConfig.API,
13+
...resourceConfig.API,
914
REST: {
10-
...existingConfig.API?.REST,
15+
...resourceConfig.API?.REST,
1116
'[API NAME]': {
1217
endpoint: '[API GATEWAY ENDPOINT]',
1318
region: '[REGION]'

src/fragments/lib/troubleshooting/common/upgrading.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Wherever you called `Amplify.configure({ aws-exports });` previously (usually in
177177
</Columns>
178178

179179
<Callout>
180-
`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.
180+
`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.
181181
</Callout>
182182

183183
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
635635
<Block name="V6">
636636
```
637637
import { Amplify } from 'aws-amplify';
638+
import { parseAmplifyConfig } from "aws-amplify/utils";
638639
import amplifyconfig from './amplifyconfiguration.json';
639640
640-
Amplify.configure(amplifyconfig);
641-
642641
const interactionsConfig = {
643642
LexV2: {
644643
'<V2BotName>': {
@@ -651,7 +650,7 @@ In v6, the `AWSLexV2Provider` provider will be included by default and you are n
651650
}
652651
653652
Amplify.configure({
654-
...Amplify.getConfig(),
653+
...parseAmplifyConfig(amplifyconfig),
655654
Interactions: interactionsConfig
656655
});
657656
```

src/pages/[platform]/build-a-backend/add-aws-services/analytics/streaming-data/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Configure Kinesis:
9393
```javascript title="src/index.js"
9494
// Configure the plugin after adding it to the Analytics module
9595
import { Amplify } from 'aws-amplify';
96+
import { parseAmplifyConfig } from "aws-amplify/utils";
9697
import outputs from '../amplify_outputs.json';
9798

9899
const amplifyConfig = parseAmplifyConfig(outputs);

src/pages/[platform]/build-a-backend/add-aws-services/predictions/set-up-predictions/index.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,13 @@ Import and load the configuration file in your app. It is recommended you add th
154154

155155
```ts title="src/main.ts"
156156
import { Amplify } from "aws-amplify";
157-
import outputs from '../amplify_outputs.json';
157+
import { parseAmplifyConfig } from "aws-amplify/utils";
158+
import outputs from './amplify_outputs.json';
158159

159-
Amplify.configure(outputs);
160+
const amplifyConfig = parseAmplifyConfig(outputs);
161+
162+
Amplify.configure({
163+
...amplifyConfig,
164+
Predictions: outputs.custom.Predictions,
165+
});
160166
```

0 commit comments

Comments
 (0)