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

feat(s3): export bucket websiteURL (#1521) #1544

Merged
merged 1 commit into from
Jan 15, 2019
Merged

feat(s3): export bucket websiteURL (#1521) #1544

merged 1 commit into from
Jan 15, 2019

Conversation

AlexChesters
Copy link
Contributor

Fixes #1521.

This exposes the WebsiteURL property (documented in the relevant CloudFormation template).


Pull Request Checklist

  • Testing
    • Unit test added
    • CLI change?: manually run integration tests and paste output as a PR comment
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
  • Title and Description
    • Change type: title prefixed with fix, feat will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • [ not needed ] Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

@AlexChesters AlexChesters requested a review from a team as a code owner January 14, 2019 15:19
@AlexChesters
Copy link
Contributor Author

This was originally implemented in #1522, however I made the diff a bit of a mess when trying to pull into some changes from master, so I've opened this PR to make it easier to review. It should have all the requested changes from #1522 implemented.

cc: @eladb, @rix0rrr - apologies for messing you guys around!

@eladb eladb merged commit 4e46d3c into aws:master Jan 15, 2019
@@ -986,4 +998,8 @@ class ImportedBucket extends BucketBase {
private generateDomainName() {
return `${this.bucketName}.s3.amazonaws.com`;
}

private generateBucketWebsiteUrl() {
return `${this.bucketName}.s3-website-${new cdk.Aws().region}.amazonaws.com`;
Copy link
Contributor

Choose a reason for hiding this comment

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

The region should be ${cdk.Stack.find(this).region}

And I think we need ${cdk.Stack.find(this).urlSuffix} instead of amazonaws.com.


Just found out is no generalized form of this. It's either:

bucket-name.s3-website-region.amazonaws.com
OR
bucket-name.s3-website.region.amazonaws.com

depending on the region :/ Grrr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Region change seems like a simple change 😄

The URL suffix seems less so. Do you know which one it is depending on which region? It's a bit ugly but we could have something like:

const suffix = cdk.Stack.find(this).urlSuffix
const region = cdk.Stack.find(this).region
const regionToSuffix = {
  'eu-west-1': `s3-website-eu-west-1.${suffix}`,
  'us-west-1': `s3-website.us-west-1.${suffix}`
}

return `${this.bucketName}.${regionToSuffix[region]}`;

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, this problem is intractable for you right now (since we may be deploying without the region being available at all), so don't worry about it. This ties into #1282, we need some kind of region information to solve this.

Leave it as is and ignore it, I was just making a mental note of this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a switch on the Props to pick between the two formats?

Looking at the list: https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints I'm tempted to call it something like bucketWebsiteNewUrlFormat?: boolean, and in the documentation mention it should be true for regions launched since 2014.

@@ -972,6 +983,7 @@ class ImportedBucket extends BucketBase {
this.bucketArn = parseBucketArn(this, props);
this.bucketName = bucketName;
this.domainName = props.bucketDomainName || this.generateDomainName();
this.bucketWebsiteUrl = props.bucketWebsiteUrl || this.generateBucketWebsiteUrl();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ALWAYS want to do this? Is there a case in which you wouldn't want the bucketWebsiteUrl set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we do. I was basing this off the current CloudFormation functionality; it will always allow you to output (and therefore read) the website URL even if web hosting is not configured.

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 15, 2019

Oh oops. I had some comments on this that I forgot to publish.

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 15, 2019

This PR is subtly wrong now.

@AlexChesters
Copy link
Contributor Author

Hi @rix0rrr,

Thanks for those comments, they look sensible 😄

I notice this PR has been merged, would you like me to open a new PR with those comments applied?

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 15, 2019

Oh if you wouldn't mind, that would be fantastic! Thanks!

@AlexChesters
Copy link
Contributor Author

I've opened #1550 @rix0rrr 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bucket construct should expose WebsiteURL
3 participants