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): cross account asset upload no longer works #12155

Merged
merged 4 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions packages/aws-cdk/lib/util/asset-publishing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class PublishingAws implements cdk_assets.IAws {
private readonly targetEnv: cxapi.Environment) {
}

public async discoverPartition(): Promise<string> {
return (await this.aws.baseCredentialsPartition(this.targetEnv, Mode.ForWriting)) ?? 'aws';
}

public async discoverDefaultRegion(): Promise<string> {
return this.targetEnv.region;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cdk-assets/bin/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class DefaultAwsClient implements IAws {
return new this.AWS.ECR(await this.awsOptions(options));
}

public async discoverPartition(): Promise<string> {
return (await this.discoverCurrentAccount()).partition;
}

public async discoverDefaultRegion(): Promise<string> {
return this.AWS.config.region || 'us-east-1';
}
Expand Down
1 change: 1 addition & 0 deletions packages/cdk-assets/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as AWS from 'aws-sdk';
* AWS SDK operations required by Asset Publishing
*/
export interface IAws {
discoverPartition(): Promise<string>;
discoverDefaultRegion(): Promise<string>;
discoverCurrentAccount(): Promise<Account>;

Expand Down
8 changes: 7 additions & 1 deletion packages/cdk-assets/lib/private/placeholders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { IAws } from '../aws';
* (they're nominally independent tools).
*/
export async function replaceAwsPlaceholders<A extends { region?: string }>(object: A, aws: IAws): Promise<A> {
let partition = async () => {
const p = await aws.discoverPartition();
partition = () => Promise.resolve(p);
return p;
};

let account = async () => {
const a = await aws.discoverCurrentAccount();
account = () => Promise.resolve(a);
Expand All @@ -22,7 +28,7 @@ export async function replaceAwsPlaceholders<A extends { region?: string }>(obje
return (await account()).accountId;
},
async partition() {
return (await account()).partition;
return partition();
redbaron marked this conversation as resolved.
Show resolved Hide resolved
},
});
}
1 change: 1 addition & 0 deletions packages/cdk-assets/test/mock-aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function mockAws() {
return {
mockEcr,
mockS3,
discoverPartition: jest.fn(() => Promise.resolve('swa')),
discoverCurrentAccount: jest.fn(() => Promise.resolve({ accountId: 'current_account', partition: 'swa' })),
discoverDefaultRegion: jest.fn(() => Promise.resolve('current_region')),
ecrClient: jest.fn(() => Promise.resolve(mockEcr)),
Expand Down