Skip to content

Commit f0ad96e

Browse files
authored
fix(cdk-assets): --profile is ignored while publishing assets (#224)
We neglected to configure the main credentials when assuming the file publishing role. The main credentials are where the profile is already configured. - Integration Test: aws/aws-cdk-cli-testing#59 Fixes #212 --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 1bef263 commit f0ad96e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/cdk-assets/lib/aws.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,24 @@ export interface Account {
126126
export class DefaultAwsClient implements IAws {
127127
private account?: Account;
128128
private config: Configuration;
129+
private readonly mainCredentials: AwsCredentialIdentityProvider;
129130

130131
constructor(private readonly profile?: string) {
131132
const clientConfig: STSClientConfig = {
132133
customUserAgent: USER_AGENT,
133134
};
135+
136+
// storing the main credentials separately because
137+
// the `config` object changes every time we assume the file publishing role.
138+
// TODO refactor to make `config` a readonly property and avoid state mutations.
139+
this.mainCredentials = fromNodeProviderChain({
140+
profile: this.profile,
141+
clientConfig,
142+
});
143+
134144
this.config = {
135145
clientConfig,
136-
credentials: fromNodeProviderChain({
137-
profile: this.profile,
138-
clientConfig,
139-
}),
146+
credentials: this.mainCredentials,
140147
};
141148
}
142149

@@ -228,6 +235,8 @@ export class DefaultAwsClient implements IAws {
228235
config.region = options.region;
229236
if (options.assumeRoleArn) {
230237
config.credentials = fromTemporaryCredentials({
238+
// dont forget the credentials chain.
239+
masterCredentials: this.mainCredentials,
231240
params: {
232241
RoleArn: options.assumeRoleArn,
233242
ExternalId: options.assumeRoleExternalId,

0 commit comments

Comments
 (0)