Skip to content

Dismantling global config object from SDK V2 #14199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e0bed28
refactor: move httpProxy out of global config
May 2, 2025
3072d5c
refactor: moved customUserAgent logic out of globalConfig
May 5, 2025
d0796bb
refactor: decouple credentials from global SDK config
May 6, 2025
72f7240
Potential fix for code scanning alert no. 1856: Unused variable, impo…
ShadowCat567 May 6, 2025
cd7444f
chore: remove unused import
May 6, 2025
87a3c9f
Merge branch 'sdk-migrations-0' of github.com:aws-amplify/amplify-cli…
May 6, 2025
e61fb0a
fix: lint errors and test failures
May 6, 2025
ce19265
fix: test failures
May 6, 2025
6d47fdd
fix: failing test, will need to revisit this later
May 6, 2025
6ac59f1
fix: testing issues (hopefully)
May 6, 2025
7202085
refactor: altered getConfigedAWSClient method
May 7, 2025
495465c
fix: install sdk in hosting category
May 7, 2025
c929ee7
fix: removed unnecessary function
May 7, 2025
2d95220
refactor: update hosting test
May 9, 2025
ce30734
chore: removed comments
May 9, 2025
8db79f5
chore: make sdk imports more specialized
May 9, 2025
e8e4481
chore: upped binary threshold size temporarily
May 9, 2025
5c4c686
chore(release): Publish tagged release sdk-v2-with-data-0
May 9, 2025
d5a2789
chore: debuggin
May 29, 2025
1d2c4ee
Merge branch 'sdk-migrations-0' of github.com:aws-amplify/amplify-cli…
May 29, 2025
5c61105
5c4c6868d2d26be83190112921b0260f5156fa46Revert "chore(release): Publi…
May 29, 2025
e6820c1
chore: better debugging
May 29, 2025
af12c1d
chore: debugging
May 30, 2025
239c710
fix: update config
May 30, 2025
b5feb31
chore: removed debugging lines
May 30, 2025
86102d6
Merge branch 'dev' into sdk-migrations-0
Jun 2, 2025
f8fef9c
chore: change output type
Jun 2, 2025
ed689aa
chore: api update
Jun 3, 2025
f808a91
Merge branch 'dev' into sdk-migrations-0
Jun 5, 2025
88afc6d
chore: feedback
Jun 6, 2025
4970d45
chore: remove unused imports
Jun 6, 2025
ec02598
fix: accidentally swapped exports
Jun 6, 2025
53e00af
chore(release): Publish tagged release pr-0-sdk-1
Jun 18, 2025
d283640
Revert "chore(release): Publish tagged release pr-0-sdk-1"
Jun 18, 2025
90e415f
fix: global config lives to fight another day
Jun 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .circleci/local_publish_helpers_codebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ function verifyPkgCli {
fi
}

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

function unsetNpmRegistryUrl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ function confirm() {
Username: userName,
};

AWS.config.region = region;

var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({ region: region });

cognitoidentityserviceprovider.confirmSignUp(params, function (err, data) {
if (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { createReadStream, readdirSync, existsSync } from 'fs-extra';
import mime from 'mime-types';
import * as path from 'path';
import { getAuthResourceName } from '../../../utils/getAuthResourceName';
import s3 from 'aws-sdk/clients/s3';

const providerName = 'awscloudformation';

const getS3Client = async (context: $TSContext, action: string): Promise<S3> => {
const providerPlugins = context.amplify.getProviderPlugins(context);
const provider = await import(providerPlugins[providerName]);
const aws = await provider.getConfiguredAWSClient(context, AmplifyCategories.AUTH, action);
return new aws.S3();
const config = await provider.getConfiguredAWSClient(context, AmplifyCategories.AUTH, action);
return new s3(config);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { $TSContext } from '@aws-amplify/amplify-cli-core';
import { prompter, printer } from '@aws-amplify/amplify-prompts';
import { existsSync, writeFileSync } from 'fs-extra';
import { join } from 'path';
import aws from 'aws-sdk';
import Location from 'aws-sdk/clients/location';
import { ServiceName } from '../service-utils/constants';
import { validateGeoJSONObj } from '../service-utils/validateGeoJSONObj';
import {
Expand Down Expand Up @@ -112,7 +112,7 @@ export const importResource = async (context: $TSContext) => {
const bulkUploadGeofence = async (context: $TSContext, params: ImportParams, region: string) => {
printer.info('Updating your Geofences in the collection...');
try {
const { client } = await context.amplify.invokePluginMethod<{ client: aws.Location }>(
const { client } = await context.amplify.invokePluginMethod<{ client: Location }>(
context,
'awscloudformation',
undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
async function getConfiguredAWSClient() {
return {
S3,
IAM,
Pinpoint,
CloudFront,
credentials: 'some credentials',
customUserAgent: 'someCustomUserAgent',
};
}

async function getConfiguredPinpointClient() {
return new Pinpoint();
}

class S3 {
upload() {
return {
promise: () => Promise.resolve({}),
};
}
}

class IAM {
createPolicy() {
return {
promise: () =>
Promise.resolve({
Policy: {},
}),
};
}

attachRolePolicy() {
return {
promise: () => Promise.resolve({}),
};
}
}

class Pinpoint {
constructor() {
this.config = {};
Expand Down Expand Up @@ -71,14 +44,6 @@ class Pinpoint {
}
}

class CloudFront {
createInvalidation() {
return {
promise: () => Promise.resolve({}),
};
}
}

module.exports = {
getConfiguredAWSClient,
getConfiguredPinpointClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const mockAwsProviderModule = require('../../../../__mocks__/mockAwsProviderModule');

const cloudFrontManager = require('../../../../lib/S3AndCloudFront/helpers/cloudfront-manager');

describe('cloudfront-manager', () => {
Expand Down Expand Up @@ -76,14 +74,9 @@ describe('cloudfront-manager', () => {
}
}

mockAwsProviderModule.getConfiguredAWSClient = () => {
return {
CloudFront: mockCloudFront,
};
};

test('invalidateCloudFront', async () => {
const result = await cloudFrontManager.invalidateCloudFront(mockContext);
const mockCloudFrontClient = async (context, action) => Promise.resolve(new mockCloudFront());
const result = await cloudFrontManager.invalidateCloudFront(mockContext, mockCloudFrontClient);
expect(result).toBe(mockContext);
expect(mockInvalidateMethod).toBeCalled();
expect(mockContext.exeInfo.cftInvalidationData).toEqual(mockcftInvalidationData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const chalk = require('chalk');
const constants = require('../../constants');
const CloudFront = require('aws-sdk/clients/cloudfront');

const providerName = 'awscloudformation';

function invalidateCloudFront(context) {
function invalidateCloudFront(context, cloudFrontClient = getCloudFrontClient) {
if (context.parameters.options.invalidateCache || context.parameters.options.invalidateCloudFront || context.parameters.options.c) {
return invalidate(context);
return invalidate(context, cloudFrontClient);
}
}

async function invalidate(context) {
async function invalidate(context, cloudFrontClient = getCloudFrontClient) {
if (context.exeInfo.serviceMeta && context.exeInfo.serviceMeta.output && context.exeInfo.serviceMeta.output.CloudFrontDistributionID) {
const { CloudFrontDistributionID } = context.exeInfo.serviceMeta.output;
const { CloudFrontSecureURL } = context.exeInfo.serviceMeta.output;

const cloudFront = await getCloudFrontClient(context, 'update');
const cloudFront = await cloudFrontClient(context, 'update');
const invalidateParams = {
DistributionId: CloudFrontDistributionID,
InvalidationBatch: {
Expand Down Expand Up @@ -43,8 +44,8 @@ async function invalidate(context) {
async function getCloudFrontClient(context, action) {
const providerPlugins = context.amplify.getProviderPlugins(context);
const provider = require(providerPlugins[providerName]);
const aws = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
return new aws.CloudFront();
const config = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
return new CloudFront(config);
}

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const sequential = require('promise-sequential');
const fileScanner = require('./file-scanner');
const constants = require('../../constants');
const { uploadFile } = require('./upload-file');
const S3 = require('aws-sdk/clients/s3');

const serviceName = 'S3AndCloudFront';
const providerName = 'awscloudformation';
Expand Down Expand Up @@ -41,8 +42,8 @@ function sortUploadFiles(fileList) {
async function getS3Client(context, action) {
const providerPlugins = context.amplify.getProviderPlugins(context);
const provider = require(providerPlugins[providerName]);
const aws = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
return new aws.S3();
const config = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
return new S3(config);
}

function getHostingBucketName(context) {
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-category-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@aws-amplify/amplify-cli-core": "4.4.1",
"@aws-amplify/amplify-prompts": "2.8.6",
"aws-sdk": "^2.1692.0",
"chalk": "^4.1.1",
"fs-extra": "^8.1.0",
"mime-types": "^2.1.26",
Expand Down
14 changes: 12 additions & 2 deletions packages/amplify-category-notifications/src/auth-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { $TSAny, $TSContext, AmplifyCategories, AmplifyError } from '@aws-amplif
import { printer } from '@aws-amplify/amplify-prompts';
import ora from 'ora';
import os from 'os';
import { ProxyAgent } from 'proxy-agent';
import IAM from 'aws-sdk/clients/iam';

const providerName = 'awscloudformation';
const policyNamePrefix = 'pinpoint_amplify-';
Expand Down Expand Up @@ -150,8 +152,16 @@ const getIamClient = async (context: $TSContext, action: string | undefined): Pr
const providerPlugins = context.amplify.getProviderPlugins(context);
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
const provider = require(providerPlugins[providerName]);
const aws = await provider.getConfiguredAWSClient(context, AmplifyCategories.NOTIFICATIONS, action);
return new aws.IAM();
let httpAgent = undefined;
const httpProxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
if (httpProxy) {
httpAgent = new ProxyAgent();
}
const config = await provider.getConfiguredAWSClient(context, AmplifyCategories.NOTIFICATIONS, action);
return new IAM({
...config,
httpOptions: { agent: httpAgent },
});
};

const getPolicyDoc = (context: $TSContext): string => {
Expand Down
18 changes: 5 additions & 13 deletions packages/amplify-category-notifications/src/pinpoint-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { PinpointName } from './pinpoint-name';
import { isChannelDeploymentDeferred } from './notifications-backend-cfg-channel-api';
import { constructResourceMeta, addPartialNotificationsAppMeta } from './notifications-amplify-meta-api';
import { addPartialNotificationsBackendConfig } from './notifications-backend-cfg-api';
import aws from 'aws-sdk';
import Pinpoint from 'aws-sdk/clients/pinpoint';
import {
formUserAgentParam,
loadConfiguration,
Expand Down Expand Up @@ -524,12 +524,7 @@ const getConfiguredCredentials = async (context: $TSContext, envName?: string):
}
};

export const getPinpointClient = async (
context: $TSContext,
category: string,
action?: string,
envName?: string,
): Promise<aws.Pinpoint> => {
export const getPinpointClient = async (context: $TSContext, category: string, action?: string, envName?: string): Promise<Pinpoint> => {
const httpProxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
const cred = await getConfiguredCredentials(context, envName);

Expand All @@ -543,17 +538,14 @@ export const getPinpointClient = async (
region: pinpointApp?.Region ?? (await mapServiceRegion(context, cred?.region || resolveRegion())),
customUserAgent: formUserAgentParam(context, userAgentAction),
};
let httpAgent = undefined;

// HTTP_PROXY & HTTPS_PROXY env vars are read automatically by ProxyAgent, but we check to see if they are set before using the proxy
if (httpProxy) {
aws.config.update({
httpOptions: {
agent: new ProxyAgent(),
},
});
httpAgent = new ProxyAgent();
}

return new aws.Pinpoint({ ...cred, ...defaultOptions });
return new Pinpoint({ ...cred, ...defaultOptions, httpOptions: { agent: httpAgent } });
};

export const mapServiceRegion = async (context: $TSContext, region: string): Promise<string> => {
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-console-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@aws-amplify/amplify-cli-core": "4.4.1",
"@aws-amplify/amplify-environment-parameters": "1.9.19",
"archiver": "^7.0.1",
"aws-sdk": "^2.1692.0",
"chalk": "^4.1.1",
"cli-table3": "^0.6.0",
"execa": "^5.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const constants = require('../constants/plugin-constants');
const AWS = require('aws-sdk');

async function getAmplifyClient(context) {
const AWS = await getAWSClient(context);
return new AWS.Amplify();
const config = await getAWSClient(context);
return new AWS.Amplify(config);
}

async function getS3Client(context) {
const AWS = await getAWSClient(context);
return new AWS.S3();
const config = await getAWSClient(context);
return new AWS.S3(config);
}

async function getAWSClient(context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const fs = require('fs-extra');
const mime = require('mime-types');
const constants = require('../constants');
const S3 = require('aws-sdk/clients/s3');

export async function getS3Client(context, action) {
const providerPlugins = context.amplify.getProviderPlugins(context);
const provider = require(providerPlugins[constants.providerName]);
const aws = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
return new aws.S3();
const config = await provider.getConfiguredAWSClient(context, constants.CategoryName, action);
return new S3(config);
}

export async function uploadFile(s3Client, bucketName, filePath, fileKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ const route = '/mock-testing';
const bucket = 'mock-testing';
const localDirS3 = __dirname + '/test-data/';

const fakeAccessId = 'fakeaccesskeyidfortesting';
const fakeSecretKey = 'fakeaccesssecretkeyfortesting';
const fakeRegion = 'eu-west-2';

let s3client;
let simulator;

jest.setTimeout(2000000);

beforeAll(async () => {
AWS.config.update({
accessKeyId: 'fakeaccesskeyidfortesting',
secretAccessKey: 'fakeaccesssecretkeyfortesting',
region: 'eu-west-2',
});

const ep = new AWS.Endpoint('http://localhost:20005');
s3client = new AWS.S3({
accessKeyId: fakeAccessId,
secretAccessKey: fakeSecretKey,
region: fakeRegion,
apiVersion: '2006-03-01',
endpoint: ep.href,
s3BucketEndpoint: true,
Expand Down
12 changes: 8 additions & 4 deletions packages/amplify-e2e-tests/src/import-helpers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ const addAppClient = async (
const projectDetails = getProjectMeta(projectRoot);
const authDetails = getAuthProjectDetails(projectRoot);
const creds = new aws.SharedIniFileCredentials({ profile: profileName });
aws.config.credentials = creds;

const cognitoClient = new aws.CognitoIdentityServiceProvider({ region: projectDetails.providers.awscloudformation.Region });
const cognitoClient = new aws.CognitoIdentityServiceProvider({
credentials: creds,
region: projectDetails.providers.awscloudformation.Region,
});
const response = await cognitoClient
.createUserPoolClient({
ClientName: clientName,
Expand Down Expand Up @@ -332,9 +334,11 @@ export const deleteAppClient = async (profileName: string, projectRoot: string,
const authDetails = getAuthProjectDetails(projectRoot);
const projectDetails = getProjectMeta(projectRoot);
const creds = new aws.SharedIniFileCredentials({ profile: profileName });
aws.config.credentials = creds;

const cognitoClient = new aws.CognitoIdentityServiceProvider({ region: projectDetails.providers.awscloudformation.Region });
const cognitoClient = new aws.CognitoIdentityServiceProvider({
credentials: creds,
region: projectDetails.providers.awscloudformation.Region,
});
await cognitoClient.deleteUserPoolClient({ ClientId: clientId, UserPoolId: authDetails.meta.UserPoolId }).promise();
};

Expand Down
6 changes: 2 additions & 4 deletions packages/amplify-provider-awscloudformation/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export const getLocationRegionMapping: () => $TSObject;
// @public (undocumented)
export const getLocationSupportedRegion: (region: string) => string;

// Warning: (ae-forgotten-export) The symbol "AwsSecrets" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "AwsSdkConfig" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function loadConfiguration(context: $TSContext): Promise<AwsSecrets>;
export function loadConfiguration(context: $TSContext): Promise<AwsSdkConfig>;

// Warning: (ae-forgotten-export) The symbol "AwsSdkConfig" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function loadConfigurationForEnv(context: $TSContext, env: string, appId?: string): Promise<AwsSdkConfig>;

Expand Down
Loading
Loading