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-patterns): support IPv6 in HttpsRedirect #10203

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-route53-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The `HttpsRedirect` constructs creates:
* Amazon CloudFront distribution - makes website available from data centres
around the world
* Amazon S3 bucket - empty bucket used for website hosting redirect (`websiteRedirect`) capabilities.
* Amazon Route 53 Alias record - routes traffic to the CloudFront distribution
* Amazon Route 53 A/AAAA Alias records - routes traffic to the CloudFront distribution
* AWS Certificate Manager certificate - SSL/TLS certificate used by
CloudFront for your domain

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as crypto from 'crypto';
import { DnsValidatedCertificate, ICertificate } from '@aws-cdk/aws-certificatemanager';
import { CloudFrontWebDistribution, OriginProtocolPolicy, PriceClass, ViewerProtocolPolicy } from '@aws-cdk/aws-cloudfront';
import { ARecord, IHostedZone, RecordTarget } from '@aws-cdk/aws-route53';
import { ARecord, AaaaRecord, IHostedZone, RecordTarget } from '@aws-cdk/aws-route53';
import { CloudFrontTarget } from '@aws-cdk/aws-route53-targets';
import { Bucket, RedirectProtocol } from '@aws-cdk/aws-s3';
import { Construct, RemovalPolicy, Stack, Token } from '@aws-cdk/core';
Expand Down Expand Up @@ -97,11 +97,13 @@ export class HttpsRedirect extends Construct {

domainNames.forEach((domainName) => {
const hash = crypto.createHash('md5').update(domainName).digest('hex').substr(0, 6);
new ARecord(this, `RedirectAliasRecord${hash}`, {
const aliasProps = {
recordName: domainName,
zone: props.zone,
target: RecordTarget.fromAlias(new CloudFrontTarget(redirectDist)),
});
};
new ARecord(this, `RedirectAliasRecord${hash}`, aliasProps);
new AaaaRecord(this, `RedirectAliasRecordSix${hash}`, aliasProps);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ test('create HTTPS redirect', () => {
},
});
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
Type: 'A',
Name: 'foo.example.com.',
HostedZoneId: 'ID',
});
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
Type: 'AAAA',
Name: 'foo.example.com.',
HostedZoneId: 'ID',
});
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
Type: 'A',
Name: 'baz.example.com.',
HostedZoneId: 'ID',
});
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
Type: 'AAAA',
Name: 'baz.example.com.',
HostedZoneId: 'ID',
});
Expand Down Expand Up @@ -68,6 +80,11 @@ test('create HTTPS redirect for apex', () => {
},
});
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
Type: 'A',
Name: 'example.com.',
});
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
Type: 'AAAA',
Name: 'example.com.',
});
});
Expand Down