From da883d3e5a18ace67f9c40b3af9da647c87757ce Mon Sep 17 00:00:00 2001 From: Clare Liguori Date: Sun, 11 Nov 2018 14:48:17 -0800 Subject: [PATCH] feat(aws-route53): route53 alias record construct --- .../aws-cloudfront/lib/web_distribution.ts | 10 +- packages/@aws-cdk/aws-cloudfront/package.json | 1 + ...nteg.cloudfront-alias-target.expected.json | 78 ++++ .../test/integ.cloudfront-alias-target.ts | 30 ++ .../lib/shared/base-load-balancer.ts | 9 +- .../aws-elasticloadbalancingv2/package.json | 1 + .../test/integ.alb-alias-target.expected.json | 382 ++++++++++++++++++ .../test/integ.alb-alias-target.ts | 26 ++ .../@aws-cdk/aws-route53/lib/records/alias.ts | 58 +++ .../@aws-cdk/aws-route53/lib/records/index.ts | 1 + .../aws-route53/test/test.alias-record.ts | 42 ++ 11 files changed, 636 insertions(+), 2 deletions(-) create mode 100644 packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.expected.json create mode 100644 packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.ts create mode 100644 packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.expected.json create mode 100644 packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.ts create mode 100644 packages/@aws-cdk/aws-route53/lib/records/alias.ts create mode 100644 packages/@aws-cdk/aws-route53/test/test.alias-record.ts diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts index fcbd3a922e51b..f6e691866fc74 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts @@ -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'; @@ -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. @@ -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], diff --git a/packages/@aws-cdk/aws-cloudfront/package.json b/packages/@aws-cdk/aws-cloudfront/package.json index 9d6790a2079c9..2a71f6886b8ea 100644 --- a/packages/@aws-cdk/aws-cloudfront/package.json +++ b/packages/@aws-cdk/aws-cloudfront/package.json @@ -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" }, diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.expected.json b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.expected.json new file mode 100644 index 0000000000000..cc30641153dc3 --- /dev/null +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.expected.json @@ -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 + } + } + } + } + } + } diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.ts b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.ts new file mode 100644 index 0000000000000..24309442e5a14 --- /dev/null +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.ts @@ -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', { + recordName: '_foo', + target: distribution +}); + +app.run(); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index 80e0e81c61ef2..71263d80b4813 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -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'; @@ -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 * @@ -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 + }; + } } diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json index ce95c748c5a4b..47d0ee029c54d 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json @@ -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" }, diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.expected.json b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.expected.json new file mode 100644 index 0000000000000..689e2b1378871 --- /dev/null +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.expected.json @@ -0,0 +1,382 @@ +{ + "Resources": { + "VPCB9E5F0B4": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC" + } + ] + } + }, + "VPCPublicSubnet1SubnetB4246D30": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.0.0/18", + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": "test-region-1a", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PublicSubnet1" + } + ] + } + }, + "VPCPublicSubnet1RouteTableFEE4B781": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PublicSubnet1" + } + ] + } + }, + "VPCPublicSubnet1RouteTableAssociation0B0896DC": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "SubnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + } + } + }, + "VPCPublicSubnet1DefaultRoute91CEF279": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet1RouteTableFEE4B781" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VPCIGWB7E252D3" + } + } + }, + "VPCPublicSubnet1EIP6AD938E8": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc" + } + }, + "VPCPublicSubnet1NATGatewayE0556630": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet1EIP6AD938E8", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PublicSubnet1" + } + ] + } + }, + "VPCPublicSubnet2Subnet74179F39": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.64.0/18", + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": "test-region-1b", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PublicSubnet2" + } + ] + } + }, + "VPCPublicSubnet2RouteTable6F1A15F1": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PublicSubnet2" + } + ] + } + }, + "VPCPublicSubnet2RouteTableAssociation5A808732": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "SubnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + } + } + }, + "VPCPublicSubnet2DefaultRouteB7481BBA": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPublicSubnet2RouteTable6F1A15F1" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VPCIGWB7E252D3" + } + } + }, + "VPCPublicSubnet2EIP4947BC00": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc" + } + }, + "VPCPublicSubnet2NATGateway3C070193": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VPCPublicSubnet2EIP4947BC00", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VPCPublicSubnet2Subnet74179F39" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PublicSubnet2" + } + ] + } + }, + "VPCPrivateSubnet1Subnet8BCA10E0": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.128.0/18", + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": "test-region-1a", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PrivateSubnet1" + } + ] + } + }, + "VPCPrivateSubnet1RouteTableBE8A6027": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PrivateSubnet1" + } + ] + } + }, + "VPCPrivateSubnet1RouteTableAssociation347902D1": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "SubnetId": { + "Ref": "VPCPrivateSubnet1Subnet8BCA10E0" + } + } + }, + "VPCPrivateSubnet1DefaultRouteAE1D6490": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet1RouteTableBE8A6027" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VPCPublicSubnet1NATGatewayE0556630" + } + } + }, + "VPCPrivateSubnet2SubnetCFCDAA7A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.192.0/18", + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "AvailabilityZone": "test-region-1b", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PrivateSubnet2" + } + ] + } + }, + "VPCPrivateSubnet2RouteTable0A19E10E": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC/PrivateSubnet2" + } + ] + } + }, + "VPCPrivateSubnet2RouteTableAssociation0C73D413": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "SubnetId": { + "Ref": "VPCPrivateSubnet2SubnetCFCDAA7A" + } + } + }, + "VPCPrivateSubnet2DefaultRouteF4F5CFD2": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "VPCPrivateSubnet2RouteTable0A19E10E" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VPCPublicSubnet2NATGateway3C070193" + } + } + }, + "VPCIGWB7E252D3": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-cdk-elbv2-integ/VPC" + } + ] + } + }, + "VPCVPCGW99B986DC": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "VpcId": { + "Ref": "VPCB9E5F0B4" + }, + "InternetGatewayId": { + "Ref": "VPCIGWB7E252D3" + } + } + }, + "LB8A12904C": { + "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", + "Properties": { + "LoadBalancerAttributes": [], + "Scheme": "internet-facing", + "SecurityGroups": [ + { + "Fn::GetAtt": [ + "LBSecurityGroup8A41EA2B", + "GroupId" + ] + } + ], + "Subnets": [ + { + "Ref": "VPCPublicSubnet1SubnetB4246D30" + }, + { + "Ref": "VPCPublicSubnet2Subnet74179F39" + } + ], + "Type": "application" + } + }, + "LBSecurityGroup8A41EA2B": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Automatically created Security Group for ELB awscdkelbv2integLB9950B1E4", + "SecurityGroupEgress": [ + { + "CidrIp": "255.255.255.255/32", + "Description": "Disallow all traffic", + "FromPort": 252, + "IpProtocol": "icmp", + "ToPort": 86 + } + ], + "SecurityGroupIngress": [], + "VpcId": { + "Ref": "VPCB9E5F0B4" + } + } + }, + "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": [ + "LB8A12904C", + "DNSName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "LB8A12904C", + "CanonicalHostedZoneID" + ] + } + }, + "HostedZoneId": { + "Ref": "HostedZoneDB99F866" + } + } + } + } +} diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.ts new file mode 100644 index 0000000000000..1226af9be4d55 --- /dev/null +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb-alias-target.ts @@ -0,0 +1,26 @@ +#!/usr/bin/env node +import ec2 = require('@aws-cdk/aws-ec2'); +import route53 = require('@aws-cdk/aws-route53'); +import cdk = require('@aws-cdk/cdk'); +import elbv2 = require('../lib'); + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'aws-cdk-elbv2-integ'); + +const vpc = new ec2.VpcNetwork(stack, 'VPC', { + maxAZs: 2 +}); + +const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { + vpc, + internetFacing: true +}); + +const zone = new route53.PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' }); + +new route53.AliasRecord(zone, 'Alias', { + recordName: '_foo', + target: lb +}); + +app.run(); diff --git a/packages/@aws-cdk/aws-route53/lib/records/alias.ts b/packages/@aws-cdk/aws-route53/lib/records/alias.ts new file mode 100644 index 0000000000000..e265700ddb869 --- /dev/null +++ b/packages/@aws-cdk/aws-route53/lib/records/alias.ts @@ -0,0 +1,58 @@ +import { Construct } from '@aws-cdk/cdk'; +import { HostedZoneRef } from '../hosted-zone-ref'; +import { cloudformation } from '../route53.generated'; +import { determineFullyQualifiedDomainName } from './_util'; + +/** + * Classes that are valid alias record targets, like CloudFront distributions and load + * balancers, should implement this interface. + */ +export interface IAliasRecordTarget { + /** + * Return hosted zone ID and DNS name, usable for Route53 alias targets + */ + asAliasRecordTarget(): AliasRecordTargetProps; +} + +/** + * Represents the properties of an alias target destination. + */ +export interface AliasRecordTargetProps { + /** + * Hosted zone ID of the target + */ + hostedZoneId: string; + + /** + * DNS name of the target + */ + dnsName: string; +} + +export interface AliasRecordProps { + /** + * Name for the record. This can be the FQDN for the record (foo.example.com) or + * a subdomain of the parent hosted zone (foo, with example.com as the hosted zone). + */ + recordName: string; + /** + * Target for the alias record + */ + target: IAliasRecordTarget; +} + +/** + * A Route53 alias record + */ +export class AliasRecord extends Construct { + constructor(parent: HostedZoneRef, id: string, props: AliasRecordProps) { + super(parent, id); + + new cloudformation.RecordSetResource(this, 'Resource', { + hostedZoneId: parent.hostedZoneId, + name: determineFullyQualifiedDomainName(props.recordName, parent), + type: 'A', // ipv4 + aliasTarget: props.target.asAliasRecordTarget() + }); + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-route53/lib/records/index.ts b/packages/@aws-cdk/aws-route53/lib/records/index.ts index 0a5b02255c22f..655c84bf4ca70 100644 --- a/packages/@aws-cdk/aws-route53/lib/records/index.ts +++ b/packages/@aws-cdk/aws-route53/lib/records/index.ts @@ -1,2 +1,3 @@ +export * from './alias'; export * from './txt'; export * from './zone-delegation'; diff --git a/packages/@aws-cdk/aws-route53/test/test.alias-record.ts b/packages/@aws-cdk/aws-route53/test/test.alias-record.ts new file mode 100644 index 0000000000000..f0eeeffa7bb38 --- /dev/null +++ b/packages/@aws-cdk/aws-route53/test/test.alias-record.ts @@ -0,0 +1,42 @@ +import { expect, haveResource } from '@aws-cdk/assert'; +import { Stack } from '@aws-cdk/cdk'; +import { Test } from 'nodeunit'; +import { AliasRecord, IAliasRecordTarget, PublicHostedZone } from '../lib'; + +export = { + 'test alias record'(test: Test) { + // GIVEN + const stack = new Stack(); + const zone = new PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' }); + + const target: IAliasRecordTarget = { + asAliasRecordTarget: () => { + return { + hostedZoneId: 'Z2P70J7EXAMPLE', + dnsName: 'foo.example.com' + }; + } + }; + + // WHEN + new AliasRecord(zone, 'Alias', { + recordName: '_foo', + target + }); + + // THEN - stack contains a record set + expect(stack).to(haveResource('AWS::Route53::RecordSet', { + Name: '_foo.test.public.', + HostedZoneId: { + Ref: 'HostedZoneDB99F866' + }, + Type: 'A', + AliasTarget: { + HostedZoneId: 'Z2P70J7EXAMPLE', + DNSName: 'foo.example.com', + } + })); + + test.done(); + } +};