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(cloudfront): Custom origins and more origin properties #9137

Merged
merged 5 commits into from
Jul 20, 2020

Conversation

njlynch
Copy link
Contributor

@njlynch njlynch commented Jul 17, 2020

Adds support to the new Distribution construct for custom HTTP origins and
more properties on both S3 and HTTP-based origins.

fixes #9106


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

Adds support to the new Distribution construct for custom HTTP origins and
more properties on both S3 and HTTP-based origins.

fixes #9106
@njlynch njlynch requested a review from a team July 17, 2020 14:07
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 17, 2020
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Looks good, but I think we should probably set the stage for a aws-cloudfront-origins module

packages/@aws-cdk/aws-cloudfront/README.md Outdated Show resolved Hide resolved
@@ -59,6 +59,17 @@ CloudFront's redirect and error handling will be used. In the latter case, the O
underlying bucket. This can be used in conjunction with a bucket that is not public to require that your users access your content using CloudFront
URLs and not S3 URLs directly.

#### From an HTTP endpoint

Origins can also be created from other resources (e.g., load balancers, API gateways), or from any accessible HTTP server, given the domain name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like a dependency issue is awaiting here... If we want to allow something like Origin.fromRestApi it means we will need this module to depend on the APIGW module (and any other CDK module for these integrations), which can be problematic from a layer standpoint.

Normally in cases like this we introduce another module (e.g. @aws-cdk/aws-cloudfront-origins) which is the "integration" module.

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 agree a new module makes sense for integrations with ALBs, APIGW, etc.

  1. Do you think that module creation should happen as part of this PR? (I'm trying to be cognizant of my PR sizes.)
  2. Would you also recommend retroactively move the S3 integration into this new module?

Here's my take:
This PR itself isn't exposing the higher-level convenience methods for LBs, gateways, etc. It's building the basic foundation to unblock non-S3 origins for customers. As far as CloudFront is (intrinsically) concerned, there are S3 bucket origins and HTTP origins. This PR solves for the latter. As future work, a aws-cloudfront-origins module should be created and populated with a few convenience methods for the most likely sources like load balancers. S3, as a "core" element of CloudFront, should stay as-is.

Copy link
Contributor

Choose a reason for hiding this comment

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

The end game (in my opinion) should be that all types of origins are defined and discoverable through -origins module. It does not really matter which ones are directly supported by CF and which ones are higher-level. From a user's perspective, all of them should be equal.

Since this is going to be a breaking change, I would encourage to create this new module and move all origin types to it earlier rather than later. Otherwise you'll risk needing to maintain the legacy.

* This method takes in the originPath, and returns it back (if undefined) or adds/removes the '/' as appropriate.
*/
private validateOriginPath(originPath?: string): string | undefined {
if (originPath === undefined) { return undefined; }
Copy link
Contributor

Choose a reason for hiding this comment

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

break if unresolved token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the appropriate way to handle this? If the input is a token at this point, it can't be validated. So just take the token as-is, and skip validation, or check & throw an error?

Suggested change
if (originPath === undefined) { return undefined; }
if (!Token.isUnresolved(originPath) && originPath === undefined) { return undefined; }

Copy link
Contributor

Choose a reason for hiding this comment

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

Yap, don't validate if it's a token.

Whitespace change.

Co-authored-by: Elad Ben-Israel <benisrae@amazon.com>
@eladb eladb added the pr/do-not-merge This PR should not be merged at this time. label Jul 20, 2020
@eladb eladb removed the pr/do-not-merge This PR should not be merged at this time. label Jul 20, 2020
@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 5cd558d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Jul 20, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit c807ff2 into master Jul 20, 2020
@mergify mergify bot deleted the njlynch/cf-custom-origins branch July 20, 2020 11:21
Chriscbr pushed a commit to Chriscbr/aws-cdk that referenced this pull request Jul 23, 2020
Adds support to the new Distribution construct for custom HTTP origins and
more properties on both S3 and HTTP-based origins.

fixes aws#9106


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
curtiseppel pushed a commit to curtiseppel/aws-cdk that referenced this pull request Aug 11, 2020
Adds support to the new Distribution construct for custom HTTP origins and
more properties on both S3 and HTTP-based origins.

fixes aws#9106


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CloudFront] Distribution - Support for custom origins
3 participants