Skip to content
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

fix(cli): mfa code is not requested when $AWS_PROFILE is used #32313

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
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
23 changes: 11 additions & 12 deletions packages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export class AwsCliCompatible {
public static async credentialChainBuilder(
options: CredentialChainOptions = {},
): Promise<AwsCredentialIdentityProvider> {
const clientConfig = {
requestHandler: AwsCliCompatible.requestHandlerBuilder(options.httpOptions),
customUserAgent: 'aws-cdk',
logger: options.logger,
};

/**
* The previous implementation matched AWS CLI behavior:
*
Expand All @@ -41,16 +47,12 @@ export class AwsCliCompatible {
profile: options.profile,
ignoreCache: true,
mfaCodeProvider: tokenCodeFn,
clientConfig: {
requestHandler: AwsCliCompatible.requestHandlerBuilder(options.httpOptions),
customUserAgent: 'aws-cdk',
logger: options.logger,
},
clientConfig,
logger: options.logger,
});
}

const profile = options.profile || process.env.AWS_PROFILE || process.env.AWS_DEFAULT_PROFILE;
const envProfile = process.env.AWS_PROFILE || process.env.AWS_DEFAULT_PROFILE;

/**
* Env AWS - EnvironmentCredentials with string AWS
Expand All @@ -74,13 +76,10 @@ export class AwsCliCompatible {
* fromInstanceMetadata()
*/
const nodeProviderChain = fromNodeProviderChain({
profile: profile,
clientConfig: {
requestHandler: AwsCliCompatible.requestHandlerBuilder(options.httpOptions),
customUserAgent: 'aws-cdk',
logger: options.logger,
},
profile: envProfile,
clientConfig,
logger: options.logger,
mfaCodeProvider: tokenCodeFn,
ignoreCache: true,
});

Expand Down
Loading