-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route53-targets): route53 record target (#14820)
Add an alias target for a Route53 record. Closes #14800 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
17 changed files
with
147 additions
and
13 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
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
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
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
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
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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
packages/@aws-cdk/aws-route53-targets/lib/route53-record.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,19 @@ | ||
import * as route53 from '@aws-cdk/aws-route53'; | ||
|
||
/** | ||
* Use another Route 53 record as an alias record target | ||
*/ | ||
export class Route53RecordTarget implements route53.IAliasRecordTarget { | ||
constructor(private readonly record: route53.IRecordSet) { | ||
} | ||
|
||
public bind(_record: route53.IRecordSet, zone?: route53.IHostedZone): route53.AliasRecordTargetConfig { | ||
if (!zone) { // zone introduced as optional to avoid a breaking change | ||
throw new Error('Cannot bind to record without a zone'); | ||
} | ||
return { | ||
dnsName: this.record.domainName, | ||
hostedZoneId: zone.hostedZoneId, | ||
}; | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
packages/@aws-cdk/aws-route53-targets/test/integ.route53-record.expected.json
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,42 @@ | ||
{ | ||
"Resources": { | ||
"HostedZoneDB99F866": { | ||
"Type": "AWS::Route53::HostedZone", | ||
"Properties": { | ||
"Name": "cdk-integ.com." | ||
} | ||
}, | ||
"WWW9F8609DA": { | ||
"Type": "AWS::Route53::RecordSet", | ||
"Properties": { | ||
"Name": "www.cdk-integ.com.", | ||
"Type": "A", | ||
"HostedZoneId": { | ||
"Ref": "HostedZoneDB99F866" | ||
}, | ||
"ResourceRecords": [ | ||
"1.2.3.4" | ||
], | ||
"TTL": "1800" | ||
} | ||
}, | ||
"Alias325C5727": { | ||
"Type": "AWS::Route53::RecordSet", | ||
"Properties": { | ||
"Name": "cdk-integ.com.", | ||
"Type": "A", | ||
"AliasTarget": { | ||
"DNSName": { | ||
"Ref": "WWW9F8609DA" | ||
}, | ||
"HostedZoneId": { | ||
"Ref": "HostedZoneDB99F866" | ||
} | ||
}, | ||
"HostedZoneId": { | ||
"Ref": "HostedZoneDB99F866" | ||
} | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/@aws-cdk/aws-route53-targets/test/integ.route53-record.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,30 @@ | ||
#!/usr/bin/env node | ||
import * as route53 from '@aws-cdk/aws-route53'; | ||
import { App, Stack } from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import * as targets from '../lib'; | ||
|
||
class TestStack extends Stack { | ||
constructor(scope: Construct, id: string) { | ||
super(scope, id); | ||
|
||
const zone = new route53.PublicHostedZone(this, 'HostedZone', { | ||
zoneName: 'cdk-integ.com', | ||
}); | ||
|
||
const www = new route53.ARecord(this, 'WWW', { | ||
zone, | ||
recordName: 'www.cdk-integ.com', | ||
target: route53.RecordTarget.fromIpAddresses('1.2.3.4'), | ||
}); | ||
|
||
new route53.ARecord(this, 'Alias', { | ||
zone, | ||
target: route53.RecordTarget.fromAlias(new targets.Route53RecordTarget(www)), | ||
}); | ||
} | ||
} | ||
|
||
const app = new App(); | ||
new TestStack(app, 'aws-cdk-r53-record-alias-target-integ'); | ||
app.synth(); |
32 changes: 32 additions & 0 deletions
32
packages/@aws-cdk/aws-route53-targets/test/route53-record.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,32 @@ | ||
import '@aws-cdk/assert-internal/jest'; | ||
import { ARecord, PublicHostedZone, RecordTarget } from '@aws-cdk/aws-route53'; | ||
import { Stack } from '@aws-cdk/core'; | ||
import { Route53RecordTarget } from '../lib'; | ||
|
||
test('use another route 53 record as record target', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const zone = new PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' }); | ||
const record = new ARecord(zone, 'Record', { | ||
zone, | ||
target: RecordTarget.fromIpAddresses('1.2.3.4'), | ||
}); | ||
|
||
// WHEN | ||
new ARecord(zone, 'Alias', { | ||
zone, | ||
target: RecordTarget.fromAlias(new Route53RecordTarget(record)), | ||
}); | ||
|
||
// THEN | ||
expect(stack).toHaveResource('AWS::Route53::RecordSet', { | ||
AliasTarget: { | ||
DNSName: { | ||
Ref: 'HostedZoneRecordB6AB510D', | ||
}, | ||
HostedZoneId: { | ||
Ref: 'HostedZoneDB99F866', | ||
}, | ||
}, | ||
}); | ||
}); |
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
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