Skip to content

Commit

Permalink
feat(s3): imported bucket format option for website URL format (#1550)
Browse files Browse the repository at this point in the history
Depending on the region, the format of the website URL may be different. Add a switch for it.
  • Loading branch information
AlexChesters authored and rix0rrr committed Jan 15, 2019
1 parent 24f521a commit 28a423d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ export interface BucketImportProps {
* @default Inferred from bucket name
*/
bucketWebsiteUrl?: string;

/**
* The format of the website URL of the bucket. This should be true for
* regions launched since 2014.
*
* @default false
*/
bucketWebsiteNewUrlFormat?: boolean;
}

/**
Expand Down Expand Up @@ -967,6 +975,7 @@ class ImportedBucket extends BucketBase {
public readonly bucketName: string;
public readonly domainName: string;
public readonly bucketWebsiteUrl: string;
public readonly bucketWebsiteNewUrlFormat: boolean;
public readonly encryptionKey?: kms.EncryptionKey;

public policy?: BucketPolicy;
Expand All @@ -985,6 +994,9 @@ class ImportedBucket extends BucketBase {
this.domainName = props.bucketDomainName || this.generateDomainName();
this.bucketWebsiteUrl = props.bucketWebsiteUrl || this.generateBucketWebsiteUrl();
this.autoCreatePolicy = false;
this.bucketWebsiteNewUrlFormat = props.bucketWebsiteNewUrlFormat === undefined
? false
: props.bucketWebsiteNewUrlFormat;
this.policy = undefined;
}

Expand All @@ -1000,6 +1012,8 @@ class ImportedBucket extends BucketBase {
}

private generateBucketWebsiteUrl() {
return `${this.bucketName}.s3-website-${new cdk.Aws().region}.amazonaws.com`;
return this.bucketWebsiteNewUrlFormat
? `${this.bucketName}.s3-website.${cdk.Stack.find(this).region}.${cdk.Stack.find(this).urlSuffix}`
: `${this.bucketName}.s3-website-${cdk.Stack.find(this).region}.${cdk.Stack.find(this).urlSuffix}`;
}
}

0 comments on commit 28a423d

Please sign in to comment.