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(route53): Domain redirect pattern #3946

Merged
merged 24 commits into from
Sep 16, 2019
Merged

feat(route53): Domain redirect pattern #3946

merged 24 commits into from
Sep 16, 2019

Conversation

hoegertn
Copy link
Contributor

@hoegertn hoegertn commented Sep 4, 2019

This implements an HTTPS redirect using a CloudFront distribution and an S3 bucket. (fix #3893)


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

@hoegertn
Copy link
Contributor Author

hoegertn commented Sep 4, 2019

This is currently work-in-progress but I wanted to get feedback early in the process.

@mergify
Copy link
Contributor

mergify bot commented Sep 4, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

@mergify
Copy link
Contributor

mergify bot commented Sep 4, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

@eladb eladb self-assigned this Sep 5, 2019
* The domain name
*
* @default - the domain name of the zone
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this only be a subdomain? Will this also support redirecting the root domain?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps call it recordName to align with route53 terminology? Provide an @example

Copy link
Contributor

Choose a reason for hiding this comment

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

@hoegertn what do you think?

originConfigs: [{
behaviors: [{ isDefaultBehavior: true }],
customOriginSource: {
domainName: Fn.select(2, Fn.split('/', redirectBucket.bucketWebsiteUrl)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure there isn’t an attribute for this already?

Copy link
Contributor

Choose a reason for hiding this comment

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

I presume that this is to remove the http:// from the website url attribute

Copy link
Contributor

@eladb eladb Sep 5, 2019

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

bucketDomainName points to the REST API endpoint, not the website endpoint. The REST API endpoint doesn't support redirects.

mystack-mybucket-kdwwxmddtr2g.s3.amazonaws.com vs http://mystack-mybucket-kdwwxmddtr2g.s3-website-us-east-2.amazonaws.com/

https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html#WebsiteRestEndpointDiff

@hoegertn may be add a comment explaining this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the bucketDomainName is the name for S3 operations but not the website domain

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we simply add another attribute to s3.Bucket? Sounds like something others can benefit from...

Copy link
Contributor

Choose a reason for hiding this comment

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

@hoegertn care to raise an issue (and make sure to reference this usage so we can track it down).

This library contains commonly used patterns for Route53:
* HTTP Redirect
```ts
new HTTPSRedirect(stack, 'Redirect', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be called HttpsRedirect


This library contains commonly used patterns for Route53:
* HTTP Redirect
```ts
Copy link
Contributor

Choose a reason for hiding this comment

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

Provide some details about what this construct does and a glimpse to the underlying implementation in a sentence.

@eladb
Copy link
Contributor

eladb commented Sep 5, 2019

@rix0rrr what do you think about the module? Does it make sense to file this under "route53"? I am not 100% convinced.

Copy link
Contributor

@jogold jogold left a comment

Choose a reason for hiding this comment

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

I think we should offer a way to redirect multiple domains to the same target domain: domain.com -> www.domain.com, domain.net -> www.domain.com, domian.com -> www.domain.com

This can be achieved using a single CloudFront distribution with multiple alternate domain names (and multiple S3 buckets and A records).

<!--END STABILITY BANNER-->

This library contains commonly used patterns for Route53:
* HTTP Redirect
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* HTTP Redirect
* HTTPS Redirect

*/
readonly domainName?: string;
/**
* The ARN of the certificate; Has to be in us-east-1
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* The ARN of the certificate; Has to be in us-east-1
* The ACM certificate; Has to be in us-east-1

originConfigs: [{
behaviors: [{ isDefaultBehavior: true }],
customOriginSource: {
domainName: Fn.select(2, Fn.split('/', redirectBucket.bucketWebsiteUrl)),
Copy link
Contributor

Choose a reason for hiding this comment

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

I presume that this is to remove the http:// from the website url attribute

@mergify
Copy link
Contributor

mergify bot commented Sep 5, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

rix0rrr and others added 11 commits September 6, 2019 14:12
Update ALL jsii dependencies to 0.16, instead of just the "jsii" tool
proper.
Bumps [aws-sdk](https://github.com/aws/aws-sdk-js) from 2.522.0 to 2.524.0.
- [Release notes](https://github.com/aws/aws-sdk-js/releases)
- [Changelog](https://github.com/aws/aws-sdk-js/blob/master/CHANGELOG.md)
- [Commits](aws/aws-sdk-js@v2.522.0...v2.524.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
See CHANGELOG
…3914)

* fix(certificatemanager): add minimum backoff

Add a minimum component to the backoff and retry timer

* fix(certificatemanager): stub out sleep

Provide stub function for sleep to allow long running sleep to
cause test to fail

* fix(certificatemanager): spy on sleep

spy on sleep function to determine total time attempted to sleep

* fix(certificatemanager): Failing test

Failing test demonstrating min sleep is as low as 4.6 seconds.

* fix(certificatemanager): increase attempts

Increase max attempts in validation, still under 10,
but such that minimum sleep duration of one minute is reached
(but not more than 3 minutes).

Can adjust tests if window is not suitable, but I find that at least
30 seconds is needed in my region
Removes the dependabot autolabeling functionality (unnecessary and confusing)
@mergify
Copy link
Contributor

mergify bot commented Sep 6, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

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.

There are still some unaddressed/unresolved comments.

## HTTPS Redirect

This construct allows creating a simple HTTP->HTTPS and domainA->domainB redirect using CloudFront and S3.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add an snippet on how to create an HTTP=>HTTPS redirect. It's not clear from this.

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 will reword this sentence. It is doing a domain redirect and http->https redirect for domainA. You cannot use this construct to redirect http->https on your app domain, as you can only have of DNS entry for your domain.

originConfigs: [{
behaviors: [{ isDefaultBehavior: true }],
customOriginSource: {
domainName: Fn.select(2, Fn.split('/', redirectBucket.bucketWebsiteUrl)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we simply add another attribute to s3.Bucket? Sounds like something others can benefit from...

@eladb eladb changed the title WIP: feat(route53-patterns): add HTTPS redirect construct WIP: feat(route53): https redirect pattern construct Sep 8, 2019
@eladb eladb changed the title WIP: feat(route53): https redirect pattern construct feat(route53): https redirect pattern Sep 9, 2019

```ts
new HttpsRedirect(stack, 'Redirect', {
domainName: 'foo.example.com',
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now recordNames

@eladb
Copy link
Contributor

eladb commented Sep 12, 2019

Any updates here?

@hoegertn
Copy link
Contributor Author

We had AWS Community Days in Germany and I did not have time. Will try to fix it tonight.

@eladb
Copy link
Contributor

eladb commented Sep 12, 2019

No worries. Just checking in. No rush of course.

@mergify
Copy link
Contributor

mergify bot commented Sep 12, 2019

Continuous integration build failed

@hoegertn
Copy link
Contributor Author

@eladb Something strange is happening on build. If I remove the dependency in decdk it fails and if I add it it does not find it. What do I have to do?

@mergify
Copy link
Contributor

mergify bot commented Sep 13, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@hoegertn hoegertn changed the title feat(route53): https redirect pattern feat(route53): Domain redirect pattern Sep 13, 2019
@jogold
Copy link
Contributor

jogold commented Sep 13, 2019

@eladb Something strange is happening on build. If I remove the dependency in decdk it fails and if I add it it does not find it. What do I have to do?

Seems like your package-lock.json is not in sync anymore with your package.json:

  • update package version to 1.8.0 in package.json
  • update all cdk dependencies in your package.json to ^1.8.0 (remove unused @aws-cdk/region-info)
  • inside aws-route53-patterns: rm -rf package-lock.json && npm i

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@eladb eladb merged commit 3ac4671 into aws:master Sep 16, 2019
eladb pushed a commit that referenced this pull request Sep 23, 2019
This implements an HTTPS redirect using a CloudFront distribution and an S3 bucket. (fix #3893)
@hoegertn hoegertn deleted the https-redirect branch September 27, 2019 07:09
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.

Add a construct to redirect traffic to another domain with HTTPS support
10 participants