Skip to content
Merged
Changes from all commits
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
26 changes: 22 additions & 4 deletions packages/@aws-cdk/toolkit-lib/lib/api/aws-auth/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,6 @@ export class SDK {

public readonly config: ConfigurationOptions;

protected readonly logger?: ISdkLogger;

private readonly accountCache;

/**
Expand Down Expand Up @@ -618,9 +616,8 @@ export class SDK {
requestHandler,
retryStrategy: new ConfiguredRetryStrategy(7, (attempt) => 300 * (2 ** attempt)),
customUserAgent: defaultCliUserAgent(),
logger,
logger: logger ? makeSdkLoggerSafeByBindingThis(logger) : undefined,
};
this.logger = logger;
this.currentRegion = region;
}

Expand Down Expand Up @@ -1075,3 +1072,24 @@ export class SDK {
}

const CURRENT_ACCOUNT_KEY = Symbol('current_account_key');

/**
* Make the SDK logger safe against raw function invocations
*
* The SDK expects the logger to be an object with a number of functions, but it
* doesn't necessarily keep 'this' bound all the time; sometimes it will copy
* functions off of the object and call them from a variable.
*
* By how JavaScript works, this drops the 'this' reference. Make sure 'this' is
* bound at all times.
*
* @see https://github.com/aws/aws-sdk-js-v3/issues/7297
*/
function makeSdkLoggerSafeByBindingThis(logger: ISdkLogger): ISdkLogger {
return {
debug: logger.debug.bind(logger),
info: logger.info.bind(logger),
warn: logger.warn.bind(logger),
error: logger.error.bind(logger),
};
}
Loading