Skip to content

Commit 28a423d

Browse files
AlexChestersrix0rrr
authored andcommitted
feat(s3): imported bucket format option for website URL format (#1550)
Depending on the region, the format of the website URL may be different. Add a switch for it.
1 parent 24f521a commit 28a423d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/@aws-cdk/aws-s3/lib/bucket.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ export interface BucketImportProps {
206206
* @default Inferred from bucket name
207207
*/
208208
bucketWebsiteUrl?: string;
209+
210+
/**
211+
* The format of the website URL of the bucket. This should be true for
212+
* regions launched since 2014.
213+
*
214+
* @default false
215+
*/
216+
bucketWebsiteNewUrlFormat?: boolean;
209217
}
210218

211219
/**
@@ -967,6 +975,7 @@ class ImportedBucket extends BucketBase {
967975
public readonly bucketName: string;
968976
public readonly domainName: string;
969977
public readonly bucketWebsiteUrl: string;
978+
public readonly bucketWebsiteNewUrlFormat: boolean;
970979
public readonly encryptionKey?: kms.EncryptionKey;
971980

972981
public policy?: BucketPolicy;
@@ -985,6 +994,9 @@ class ImportedBucket extends BucketBase {
985994
this.domainName = props.bucketDomainName || this.generateDomainName();
986995
this.bucketWebsiteUrl = props.bucketWebsiteUrl || this.generateBucketWebsiteUrl();
987996
this.autoCreatePolicy = false;
997+
this.bucketWebsiteNewUrlFormat = props.bucketWebsiteNewUrlFormat === undefined
998+
? false
999+
: props.bucketWebsiteNewUrlFormat;
9881000
this.policy = undefined;
9891001
}
9901002

@@ -1000,6 +1012,8 @@ class ImportedBucket extends BucketBase {
10001012
}
10011013

10021014
private generateBucketWebsiteUrl() {
1003-
return `${this.bucketName}.s3-website-${new cdk.Aws().region}.amazonaws.com`;
1015+
return this.bucketWebsiteNewUrlFormat
1016+
? `${this.bucketName}.s3-website.${cdk.Stack.find(this).region}.${cdk.Stack.find(this).urlSuffix}`
1017+
: `${this.bucketName}.s3-website-${cdk.Stack.find(this).region}.${cdk.Stack.find(this).urlSuffix}`;
10041018
}
10051019
}

0 commit comments

Comments
 (0)