Skip to content

Commit 72db54e

Browse files
ShadowCat567aws-amplify-botgithub-advanced-security[bot]Vieltojarvi
authored
Dismantling global config object from SDK V2 (#14199)
* refactor: move httpProxy out of global config * refactor: moved customUserAgent logic out of globalConfig * refactor: decouple credentials from global SDK config * Potential fix for code scanning alert no. 1856: Unused variable, import, function or class Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * chore: remove unused import * fix: lint errors and test failures * fix: test failures * fix: failing test, will need to revisit this later * fix: testing issues (hopefully) * refactor: altered getConfigedAWSClient method * fix: install sdk in hosting category * fix: removed unnecessary function * refactor: update hosting test * chore: removed comments * chore: make sdk imports more specialized * chore: upped binary threshold size temporarily * chore(release): Publish tagged release sdk-v2-with-data-0 - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - amplify-dotnet-function-runtime-provider@2.1.5-sdk-v2-with-data-0.0 - @aws-amplify/amplify-dotnet-function-template-provider@2.7.5-sdk-v2-with-data-0.0 - [email protected] - @aws-amplify/[email protected] - [email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - [email protected] - @aws-amplify/[email protected] - [email protected] - amplify-java-function-runtime-provider@2.3.52-sdk-v2-with-data-0.0 - @aws-amplify/[email protected] - amplify-nodejs-function-runtime-provider@2.5.30-sdk-v2-with-data-0.0 - @aws-amplify/amplify-nodejs-function-template-provider@2.10.15-sdk-v2-with-data-0.0 - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - amplify-python-function-runtime-provider@2.4.52-sdk-v2-with-data-0.0 - [email protected] - [email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] * chore: debuggin * 5c4c6868d2d26be83190112921b0260f5156fa46Revert "chore(release): Publish tagged release sdk-v2-with-data-0" This reverts commit 5c4c686. * chore: better debugging * chore: debugging * fix: update config * chore: removed debugging lines * chore: change output type * chore: api update * chore: feedback * chore: remove unused imports * fix: accidentally swapped exports * chore(release): Publish tagged release pr-0-sdk-1 - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - [email protected] - @aws-amplify/[email protected] - [email protected] - @aws-amplify/[email protected] - [email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - [email protected] - @aws-amplify/[email protected] - [email protected] - [email protected] - @aws-amplify/[email protected] - [email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] - [email protected] - [email protected] - [email protected] - @aws-amplify/[email protected] - @aws-amplify/[email protected] * Revert "chore(release): Publish tagged release pr-0-sdk-1" This reverts commit 53e00af. * fix: global config lives to fight another day --------- Co-authored-by: aws-amplify-bot <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Vieltojarvi <[email protected]>
1 parent 1650100 commit 72db54e

File tree

45 files changed

+312
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+312
-177
lines changed

.circleci/local_publish_helpers_codebuild.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ function verifyPkgCli {
139139
fi
140140
}
141141

142-
verifySinglePkg "amplify-pkg-linux-x64" "amplify-pkg-linux-x64.tgz" $((930 * 1024 * 1024))
143-
verifySinglePkg "amplify-pkg-macos-x64" "amplify-pkg-macos-x64.tgz" $((930 * 1024 * 1024))
144-
verifySinglePkg "amplify-pkg-win-x64.exe" "amplify-pkg-win-x64.tgz" $((930 * 1024 * 1024))
145-
verifySinglePkg "amplify-pkg-linux-arm64" "amplify-pkg-linux-arm64.tgz" $((750 * 1024 * 1024))
142+
# TODO: After V3 migrations are done, decrease 995 back to 930 and 825 back to 750
143+
verifySinglePkg "amplify-pkg-linux-x64" "amplify-pkg-linux-x64.tgz" $((995 * 1024 * 1024))
144+
verifySinglePkg "amplify-pkg-macos-x64" "amplify-pkg-macos-x64.tgz" $((995 * 1024 * 1024))
145+
verifySinglePkg "amplify-pkg-win-x64.exe" "amplify-pkg-win-x64.tgz" $((995 * 1024 * 1024))
146+
verifySinglePkg "amplify-pkg-linux-arm64" "amplify-pkg-linux-arm64.tgz" $((825 * 1024 * 1024))
146147
}
147148

148149
function unsetNpmRegistryUrl {

packages/amplify-category-auth/provider-utils/awscloudformation/triggers/CustomMessage/assets/verify.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ function confirm() {
3737
Username: userName,
3838
};
3939

40-
AWS.config.region = region;
41-
42-
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
40+
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({ region: region });
4341

4442
cognitoidentityserviceprovider.confirmSignUp(params, function (err, data) {
4543
if (err) {

packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/trigger-file-uploader.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { createReadStream, readdirSync, existsSync } from 'fs-extra';
44
import mime from 'mime-types';
55
import * as path from 'path';
66
import { getAuthResourceName } from '../../../utils/getAuthResourceName';
7+
import s3 from 'aws-sdk/clients/s3';
78

89
const providerName = 'awscloudformation';
910

1011
const getS3Client = async (context: $TSContext, action: string): Promise<S3> => {
1112
const providerPlugins = context.amplify.getProviderPlugins(context);
1213
const provider = await import(providerPlugins[providerName]);
13-
const aws = await provider.getConfiguredAWSClient(context, AmplifyCategories.AUTH, action);
14-
return new aws.S3();
14+
const config = await provider.getConfiguredAWSClientConfig(context, AmplifyCategories.AUTH, action);
15+
return new s3(config);
1516
};
1617

1718
/**

packages/amplify-category-geo/src/provider-controllers/import.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { $TSContext } from '@aws-amplify/amplify-cli-core';
33
import { prompter, printer } from '@aws-amplify/amplify-prompts';
44
import { existsSync, writeFileSync } from 'fs-extra';
55
import { join } from 'path';
6-
import aws from 'aws-sdk';
6+
import Location from 'aws-sdk/clients/location';
77
import { ServiceName } from '../service-utils/constants';
88
import { validateGeoJSONObj } from '../service-utils/validateGeoJSONObj';
99
import {
@@ -112,7 +112,7 @@ export const importResource = async (context: $TSContext) => {
112112
const bulkUploadGeofence = async (context: $TSContext, params: ImportParams, region: string) => {
113113
printer.info('Updating your Geofences in the collection...');
114114
try {
115-
const { client } = await context.amplify.invokePluginMethod<{ client: aws.Location }>(
115+
const { client } = await context.amplify.invokePluginMethod<{ client: Location }>(
116116
context,
117117
'awscloudformation',
118118
undefined,
Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
1-
async function getConfiguredAWSClient() {
1+
async function getConfiguredAWSClientConfig() {
22
return {
3-
S3,
4-
IAM,
5-
Pinpoint,
6-
CloudFront,
3+
credentials: 'some credentials',
4+
customUserAgent: 'someCustomUserAgent',
75
};
86
}
97

108
async function getConfiguredPinpointClient() {
119
return new Pinpoint();
1210
}
1311

14-
class S3 {
15-
upload() {
16-
return {
17-
promise: () => Promise.resolve({}),
18-
};
19-
}
20-
}
21-
22-
class IAM {
23-
createPolicy() {
24-
return {
25-
promise: () =>
26-
Promise.resolve({
27-
Policy: {},
28-
}),
29-
};
30-
}
31-
32-
attachRolePolicy() {
33-
return {
34-
promise: () => Promise.resolve({}),
35-
};
36-
}
37-
}
38-
3912
class Pinpoint {
4013
constructor() {
4114
this.config = {};
@@ -71,15 +44,7 @@ class Pinpoint {
7144
}
7245
}
7346

74-
class CloudFront {
75-
createInvalidation() {
76-
return {
77-
promise: () => Promise.resolve({}),
78-
};
79-
}
80-
}
81-
8247
module.exports = {
83-
getConfiguredAWSClient,
48+
getConfiguredAWSClientConfig,
8449
getConfiguredPinpointClient,
8550
};

packages/amplify-category-hosting/__tests__/lib/S3AndCloudFront/helpers/cloudfront-manager.test.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const mockAwsProviderModule = require('../../../../__mocks__/mockAwsProviderModule');
2-
31
const cloudFrontManager = require('../../../../lib/S3AndCloudFront/helpers/cloudfront-manager');
42

53
describe('cloudfront-manager', () => {
@@ -76,14 +74,9 @@ describe('cloudfront-manager', () => {
7674
}
7775
}
7876

79-
mockAwsProviderModule.getConfiguredAWSClient = () => {
80-
return {
81-
CloudFront: mockCloudFront,
82-
};
83-
};
84-
8577
test('invalidateCloudFront', async () => {
86-
const result = await cloudFrontManager.invalidateCloudFront(mockContext);
78+
const mockCloudFrontClient = async (context, action) => Promise.resolve(new mockCloudFront());
79+
const result = await cloudFrontManager.invalidateCloudFront(mockContext, mockCloudFrontClient);
8780
expect(result).toBe(mockContext);
8881
expect(mockInvalidateMethod).toBeCalled();
8982
expect(mockContext.exeInfo.cftInvalidationData).toEqual(mockcftInvalidationData);

packages/amplify-category-hosting/lib/S3AndCloudFront/helpers/cloudfront-manager.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
const chalk = require('chalk');
22
const constants = require('../../constants');
3+
const CloudFront = require('aws-sdk/clients/cloudfront');
34

45
const providerName = 'awscloudformation';
56

6-
function invalidateCloudFront(context) {
7+
function invalidateCloudFront(context, cloudFrontClient = getCloudFrontClient) {
78
if (context.parameters.options.invalidateCache || context.parameters.options.invalidateCloudFront || context.parameters.options.c) {
8-
return invalidate(context);
9+
return invalidate(context, cloudFrontClient);
910
}
1011
}
1112

12-
async function invalidate(context) {
13+
async function invalidate(context, cloudFrontClient = getCloudFrontClient) {
1314
if (context.exeInfo.serviceMeta && context.exeInfo.serviceMeta.output && context.exeInfo.serviceMeta.output.CloudFrontDistributionID) {
1415
const { CloudFrontDistributionID } = context.exeInfo.serviceMeta.output;
1516
const { CloudFrontSecureURL } = context.exeInfo.serviceMeta.output;
1617

17-
const cloudFront = await getCloudFrontClient(context, 'update');
18+
const cloudFront = await cloudFrontClient(context, 'update');
1819
const invalidateParams = {
1920
DistributionId: CloudFrontDistributionID,
2021
InvalidationBatch: {
@@ -43,8 +44,8 @@ async function invalidate(context) {
4344
async function getCloudFrontClient(context, action) {
4445
const providerPlugins = context.amplify.getProviderPlugins(context);
4546
const provider = require(providerPlugins[providerName]);
46-
const aws = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
47-
return new aws.CloudFront();
47+
const config = await provider.getConfiguredAWSClientConfig(context, constants.CategoryName, action);
48+
return new CloudFront(config);
4849
}
4950

5051
module.exports = {

packages/amplify-category-hosting/lib/S3AndCloudFront/helpers/file-uploader.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const sequential = require('promise-sequential');
33
const fileScanner = require('./file-scanner');
44
const constants = require('../../constants');
55
const { uploadFile } = require('./upload-file');
6+
const S3 = require('aws-sdk/clients/s3');
67

78
const serviceName = 'S3AndCloudFront';
89
const providerName = 'awscloudformation';
@@ -41,8 +42,8 @@ function sortUploadFiles(fileList) {
4142
async function getS3Client(context, action) {
4243
const providerPlugins = context.amplify.getProviderPlugins(context);
4344
const provider = require(providerPlugins[providerName]);
44-
const aws = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
45-
return new aws.S3();
45+
const config = await provider.getConfiguredAWSClientConfig(context, constants.CategoryName, action);
46+
return new S3(config);
4647
}
4748

4849
function getHostingBucketName(context) {

packages/amplify-category-hosting/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"@aws-amplify/amplify-cli-core": "4.4.1",
2525
"@aws-amplify/amplify-prompts": "2.8.6",
26+
"aws-sdk": "^2.1692.0",
2627
"chalk": "^4.1.1",
2728
"fs-extra": "^8.1.0",
2829
"mime-types": "^2.1.26",

packages/amplify-category-notifications/src/auth-helper.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { $TSAny, $TSContext, AmplifyCategories, AmplifyError } from '@aws-amplif
22
import { printer } from '@aws-amplify/amplify-prompts';
33
import ora from 'ora';
44
import os from 'os';
5+
import IAM from 'aws-sdk/clients/iam';
56

67
const providerName = 'awscloudformation';
78
const policyNamePrefix = 'pinpoint_amplify-';
@@ -150,8 +151,10 @@ const getIamClient = async (context: $TSContext, action: string | undefined): Pr
150151
const providerPlugins = context.amplify.getProviderPlugins(context);
151152
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
152153
const provider = require(providerPlugins[providerName]);
153-
const aws = await provider.getConfiguredAWSClient(context, AmplifyCategories.NOTIFICATIONS, action);
154-
return new aws.IAM();
154+
const config = await provider.getConfiguredAWSClientConfig(context, AmplifyCategories.NOTIFICATIONS, action);
155+
return new IAM({
156+
...config,
157+
});
155158
};
156159

157160
const getPolicyDoc = (context: $TSContext): string => {

0 commit comments

Comments
 (0)