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(aws-route53): L2 for alias record set #1131

Merged
merged 1 commit into from
Nov 12, 2018
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
10 changes: 9 additions & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import route53 = require('@aws-cdk/aws-route53');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import { cloudformation } from './cloudfront.generated';
Expand Down Expand Up @@ -476,7 +477,7 @@ interface BehaviorWithOrigin extends Behavior {
*
*
*/
export class CloudFrontWebDistribution extends cdk.Construct {
export class CloudFrontWebDistribution extends cdk.Construct implements route53.IAliasRecordTarget {

/**
* The hosted zone Id if using an alias record in Route53.
Expand Down Expand Up @@ -659,6 +660,13 @@ export class CloudFrontWebDistribution extends cdk.Construct {
this.distributionId = distribution.distributionId;
}

public asAliasRecordTarget(): route53.AliasRecordTargetProps {
return {
hostedZoneId: this.aliasHostedZoneId,
dnsName: this.domainName
};
}

private toBehavior(input: BehaviorWithOrigin, protoPolicy?: ViewerProtocolPolicy) {
let toReturn = {
allowedMethods: this.METHOD_LOOKUP_MAP[input.allowedMethods || CloudFrontAllowedMethods.GET_HEAD],
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@aws-cdk/aws-certificatemanager": "^0.15.2",
"@aws-cdk/aws-iam": "^0.15.2",
"@aws-cdk/aws-kms": "^0.15.2",
"@aws-cdk/aws-route53": "^0.15.2",
"@aws-cdk/aws-s3": "^0.15.2",
"@aws-cdk/cdk": "^0.15.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"Resources": {
"HostedZoneDB99F866": {
"Type": "AWS::Route53::HostedZone",
"Properties": {
"Name": "test.public."
}
},
"HostedZoneAlias40D2E006": {
"Type": "AWS::Route53::RecordSet",
"Properties": {
"Name": "_foo.test.public.",
"Type": "A",
"AliasTarget": {
"DNSName": {
"Fn::GetAtt": [
"MyDistributionCFDistributionDE147309",
"DomainName"
]
},
"HostedZoneId": "Z2FDTNDATAQYW2"
},
"HostedZoneId": {
"Ref": "HostedZoneDB99F866"
}
}
},
"Bucket83908E77": {
"Type": "AWS::S3::Bucket"
},
"MyDistributionCFDistributionDE147309": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"CacheBehaviors": [],
"DefaultCacheBehavior": {
"AllowedMethods": [
"GET",
"HEAD"
],
"CachedMethods": [
"GET",
"HEAD"
],
"ForwardedValues": {
"Cookies": {
"Forward": "none"
},
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
},
"DefaultRootObject": "index.html",
"Enabled": true,
"HttpVersion": "http2",
"IPV6Enabled": true,
"Origins": [
{
"DomainName": {
"Fn::GetAtt": [
"Bucket83908E77",
"DomainName"
]
},
"Id": "origin1",
"S3OriginConfig": {}
}
],
"PriceClass": "PriceClass_100",
"ViewerCertificate": {
"CloudFrontDefaultCertificate": true
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import route53 = require('@aws-cdk/aws-route53');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import cloudfront = require('../lib');

const app = new cdk.App();

const stack = new cdk.Stack(app, 'aws-cdk-cloudfront');

const zone = new route53.PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' });

const sourceBucket = new s3.Bucket(stack, 'Bucket');

const distribution = new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', {
originConfigs: [
{
s3OriginSource: {
s3BucketSource: sourceBucket
},
behaviors : [ {isDefaultBehavior: true}]
}
]
});

new route53.AliasRecord(zone, 'Alias', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ew, do records have to be constructed under the zone that they need to be created in?

That's not according to how we design most of the construct library. But the R53 library is quite old, so it makes sense that it's not up-to-date with the latest guidelines.

Not your problem.

recordName: '_foo',
target: distribution
});

app.run();
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ec2 = require('@aws-cdk/aws-ec2');
import route53 = require('@aws-cdk/aws-route53');
import cdk = require('@aws-cdk/cdk');
import { cloudformation } from '../elasticloadbalancingv2.generated';
import { Attributes, ifUndefined, renderAttributes } from './util';
Expand Down Expand Up @@ -44,7 +45,7 @@ export interface BaseLoadBalancerProps {
/**
* Base class for both Application and Network Load Balancers
*/
export abstract class BaseLoadBalancer extends cdk.Construct {
export abstract class BaseLoadBalancer extends cdk.Construct implements route53.IAliasRecordTarget {
/**
* The canonical hosted zone ID of this load balancer
*
Expand Down Expand Up @@ -135,4 +136,10 @@ export abstract class BaseLoadBalancer extends cdk.Construct {
this.setAttribute(key, undefined);
}

public asAliasRecordTarget(): route53.AliasRecordTargetProps {
return {
hostedZoneId: this.canonicalHostedZoneId,
dnsName: this.dnsName
};
}
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-elasticloadbalancingv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@aws-cdk/aws-codedeploy-api": "^0.15.2",
"@aws-cdk/aws-ec2": "^0.15.2",
"@aws-cdk/aws-iam": "^0.15.2",
"@aws-cdk/aws-route53": "^0.15.2",
"@aws-cdk/aws-s3": "^0.15.2",
"@aws-cdk/cdk": "^0.15.2"
},
Expand Down
Loading