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

Draft
wants to merge 25 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function confirm() {
Username: userName,
};

AWS.config.region = region;
// 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 AWS from 'aws-sdk';

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 AWS.S3(config);
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const chalk = require('chalk');
const constants = require('../../constants');
const AWS = require('aws-sdk');

const providerName = 'awscloudformation';

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 AWS.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 { AWS } = require('aws-sdk');

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 AWS.S3(config);
}

function getHostingBucketName(context) {
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 AWS from 'aws-sdk';

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 AWS.IAM({
...config,
httpOptions: { agent: httpAgent },
});
};

const getPolicyDoc = (context: $TSContext): string => {
Expand Down
14 changes: 8 additions & 6 deletions packages/amplify-category-notifications/src/pinpoint-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,19 @@ 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();
// aws.config.update({
// httpOptions: {
// agent: new ProxyAgent(),
// },
// });
}

return new aws.Pinpoint({ ...cred, ...defaultOptions });
return new aws.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
17 changes: 13 additions & 4 deletions packages/amplify-console-hosting/src/utils/client-factory.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
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);
const provider = getAWSProvider(context);
return new AWS.Amplify(config);
}

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

// **this is a problem and needs to be fixed
async function getAWSClient(context) {
const providerPlugin = context.amplify.getProviderPlugins(context);
const provider = require(providerPlugin[constants.PROVIDER]);
return await provider.getConfiguredAWSClient(context, constants.CATEGORY, 'create');
}

function getAWSProvider(context) {
const providerPlugin = context.amplify.getProviderPlugins(context);
return require(providerPlugin[constants.PROVIDER]);
}

module.exports = {
getAmplifyClient,
getS3Client,
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 AWS = require('aws-sdk');

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 AWS.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,27 @@ 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',
});
// 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
14 changes: 10 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,12 @@ const addAppClient = async (
const projectDetails = getProjectMeta(projectRoot);
const authDetails = getAuthProjectDetails(projectRoot);
const creds = new aws.SharedIniFileCredentials({ profile: profileName });
aws.config.credentials = creds;
//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 +335,12 @@ 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;
//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
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const aws = require('aws-sdk');
const { ProxyAgent } = require('proxy-agent');
// const { ProxyAgent } = require('proxy-agent');
const configurationManager = require('../configuration-manager');
const { regions: amplifyServiceRegions } = require('../aws-regions');
const { proxyAgent } = require('./aws-globals');

async function getConfiguredAmplifyClient(context, options = {}) {
let cred = {};
let defaultOptions = {};
const httpProxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
// const httpProxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
const envVarEndpoint = process.env.AWS_AMPLIFY_ENDPOINT;

try {
Expand All @@ -21,15 +22,23 @@ async function getConfiguredAmplifyClient(context, options = {}) {
};
}

if (httpProxy) {
aws.config.update({
httpOptions: {
agent: new ProxyAgent(),
},
});
}
// **affected by SDK migrations
// if (httpProxy) {
// aws.config.update({
// httpOptions: {
// agent: new ProxyAgent(),
// },
// });
// }

const config = { ...cred, ...defaultOptions, ...options };
const config = {
...cred,
...defaultOptions,
...options,
httpOptions: {
agent: proxyAgent(),
},
};

// this is the "project" config level case, creds and region are explicitly set or retrieved from a profile
if (config.region) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { $TSContext } from '@aws-amplify/amplify-cli-core';
import aws from './aws.js';
import { APIGateway as APIGW } from 'aws-sdk';
import { loadConfiguration } from '../configuration-manager';
import { proxyAgent } from './aws-globals';

export class APIGateway {
private static instance: APIGateway;
Expand All @@ -24,6 +25,12 @@ export class APIGateway {

constructor(context: $TSContext, creds, options = {}) {
this.context = context;
this.apigw = new aws.APIGateway({ ...creds, ...options });
this.apigw = new aws.APIGateway({
...creds,
...options,
httpOptions: {
agent: proxyAgent(),
},
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const aws = require('./aws.js');
const configurationManager = require('../configuration-manager');
const { proxyAgent } = require('./aws-globals');

class AppSync {
constructor(context, options = {}) {
Expand All @@ -12,7 +13,13 @@ class AppSync {
}

this.context = context;
this.appSync = new aws.AppSync({ ...cred, ...options });
this.appSync = new aws.AppSync({
...cred,
...options,
httpOptions: {
agent: proxyAgent(),
},
});
return this;
})();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { initializeProgressBars } = require('./aws-cfn-progress-formatter');
const { getStatusToErrorMsg, collectStackErrorMessages } = require('./cloudformation-error-serializer');

const { printer } = require('@aws-amplify/amplify-prompts');
const { proxyAgent } = require('./aws-globals');

const CFN_MAX_CONCURRENT_REQUEST = 5;
const CFN_POLL_TIME = (process.env.IS_AMPLIFY_CI ? 30 : 5) * 1000; // 5 secs wait to check if new stacks are created by root stack
Expand Down Expand Up @@ -55,7 +56,14 @@ class CloudFormation {
userAgentOption.customUserAgent = userAgentParam;
}

this.cfn = new aws.CloudFormation({ ...cred, ...options, ...userAgentOption });
this.cfn = new aws.CloudFormation({
...cred,
...options,
...userAgentOption,
httpOptions: {
agent: proxyAgent(),
},
});
this.context = context;
if (Object.keys(eventMap).length) {
this.eventMap = eventMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { $TSContext } from '@aws-amplify/amplify-cli-core';
import aws from './aws.js';
import * as AWS from 'aws-sdk';
import { AwsSecrets, loadConfiguration } from '../configuration-manager';
import { proxyAgent } from './aws-globals';

export class CognitoUserPoolClientProvider {
private static instance: CognitoUserPoolClientProvider;
Expand All @@ -22,6 +23,12 @@ export class CognitoUserPoolClientProvider {
}

constructor(creds: AwsSecrets, options = {}) {
this.client = new aws.CognitoIdentityServiceProvider({ ...creds, ...options });
this.client = new aws.CognitoIdentityServiceProvider({
...creds,
...options,
httpOptions: {
agent: proxyAgent(),
},
});
}
}
Loading
Loading