forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route53): add classic elb target support (aws#3380)
* feat(route53-targets): add classic elb target support * fix(route53-targets): doc example Co-Authored-By: Jonathan Goldwasser <jogold@users.noreply.github.com> * chore(route53): fix export ordering
- Loading branch information
1 parent
1509399
commit b0720dd
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/@aws-cdk/aws-route53-targets/lib/classic-load-balancer-target.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import elb = require('@aws-cdk/aws-elasticloadbalancing'); | ||
import route53 = require('@aws-cdk/aws-route53'); | ||
|
||
/** | ||
* Use a classic ELB as an alias record target | ||
*/ | ||
export class ClassicLoadBalancerTarget implements route53.IAliasRecordTarget { | ||
constructor(private readonly loadBalancer: elb.LoadBalancer) { | ||
} | ||
|
||
public bind(_record: route53.IRecordSet): route53.AliasRecordTargetConfig { | ||
return { | ||
hostedZoneId: this.loadBalancer.loadBalancerCanonicalHostedZoneNameId, | ||
dnsName: this.loadBalancer.loadBalancerDnsName | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './api-gateway-domain-name'; | ||
export * from './classic-load-balancer-target'; | ||
export * from './cloudfront-target'; | ||
export * from './load-balancer-target'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/@aws-cdk/aws-route53-targets/test/classic-load-balancer-target.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import '@aws-cdk/assert/jest'; | ||
import ec2 = require('@aws-cdk/aws-ec2'); | ||
import elb = require('@aws-cdk/aws-elasticloadbalancing'); | ||
import route53 = require('@aws-cdk/aws-route53'); | ||
import { Stack } from '@aws-cdk/core'; | ||
import targets = require('../lib'); | ||
|
||
test('use classic ELB as record target', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const vpc = new ec2.Vpc(stack, 'VPC', { | ||
maxAzs: 2 | ||
}); | ||
const lb = new elb.LoadBalancer(stack, 'LB', { | ||
vpc, | ||
internetFacing: true | ||
}); | ||
|
||
const zone = new route53.PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' }); | ||
|
||
// WHEN | ||
new route53.ARecord(zone, 'Alias', { | ||
zone, | ||
recordName: '_foo', | ||
target: route53.AddressRecordTarget.fromAlias(new targets.ClassicLoadBalancerTarget(lb)) | ||
}); | ||
|
||
// THEN | ||
expect(stack).toHaveResource('AWS::Route53::RecordSet', { | ||
AliasTarget: { | ||
DNSName: { "Fn::GetAtt": [ "LB8A12904C", "DNSName" ] }, | ||
HostedZoneId: { "Fn::GetAtt": [ "LB8A12904C", "CanonicalHostedZoneNameID" ] } | ||
}, | ||
}); | ||
}); |