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
17 changes: 13 additions & 4 deletions packages/cdk-assets/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,24 @@ export interface Account {
export class DefaultAwsClient implements IAws {
private account?: Account;
private config: Configuration;
private readonly mainCredentials: AwsCredentialIdentityProvider;

constructor(private readonly profile?: string) {
const clientConfig: STSClientConfig = {
customUserAgent: USER_AGENT,
};

// storing the main credentials separately because
// the `config` object changes every time we assume the file publishing role.
// TODO refactor to make `config` a readonly property and avoid state mutations.
this.mainCredentials = fromNodeProviderChain({
profile: this.profile,
clientConfig,
});

this.config = {
clientConfig,
credentials: fromNodeProviderChain({
profile: this.profile,
clientConfig,
}),
credentials: this.mainCredentials,
};
}

Expand Down Expand Up @@ -228,6 +235,8 @@ export class DefaultAwsClient implements IAws {
config.region = options.region;
if (options.assumeRoleArn) {
config.credentials = fromTemporaryCredentials({
// dont forget the credentials chain.
masterCredentials: this.mainCredentials,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have something similar in CDK CLI:

masterCredentials: mainCredentials.credentials,

params: {
RoleArn: options.assumeRoleArn,
ExternalId: options.assumeRoleExternalId,
Expand Down