Skip to content

Commit 9900ca7

Browse files
committed
feat: update the readme and integration tests
1 parent a60e304 commit 9900ca7

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { App, Duration, Stack, StackProps } from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import * as route53 from 'aws-cdk-lib/aws-route53';
4+
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
5+
6+
class TestStack extends Stack {
7+
constructor(scope: Construct, id: string, props?: StackProps) {
8+
super(scope, id, props);
9+
10+
const hostedZone = new route53.PublicHostedZone(this, 'HostedZone', {
11+
zoneName: 'cdk.dev',
12+
});
13+
14+
const healthCheck = new route53.HealthCheck(this, 'HealthCheck', {
15+
type: route53.HealthCheckType.HTTP,
16+
fqdn: 'example.com',
17+
port: 80,
18+
resourcePath: '/health',
19+
failureThreshold: 3,
20+
requestInterval: Duration.seconds(30),
21+
});
22+
23+
// Primary failover record with health check
24+
new route53.ARecord(this, 'ARecordFailoverPrimary', {
25+
zone: hostedZone,
26+
recordName: 'failover',
27+
target: route53.RecordTarget.fromIpAddresses('1.2.3.4'),
28+
failover: route53.Failover.PRIMARY,
29+
healthCheck,
30+
setIdentifier: 'failover-primary',
31+
ttl: Duration.seconds(60),
32+
});
33+
34+
// Secondary failover record
35+
new route53.ARecord(this, 'ARecordFailoverSecondary', {
36+
zone: hostedZone,
37+
recordName: 'failover',
38+
target: route53.RecordTarget.fromIpAddresses('5.6.7.8'),
39+
failover: route53.Failover.SECONDARY,
40+
setIdentifier: 'failover-secondary',
41+
ttl: Duration.seconds(60),
42+
});
43+
}
44+
}
45+
46+
const app = new App();
47+
const stack = new TestStack(app, 'failover-record');
48+
49+
new IntegTest(app, 'Route53FailoverRecordInteg', {
50+
testCases: [stack],
51+
});
52+
app.synth();

packages/aws-cdk-lib/aws-route53/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,36 @@ new route53.ARecord(this, 'ARecordLatency1', {
216216
});
217217
```
218218

219+
To enable [failover routing](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-failover.html), use the `failover` parameter:
220+
221+
```ts
222+
declare const myZone: route53.HostedZone;
223+
224+
const healthCheck = new route53.HealthCheck(this, 'HealthCheck', {
225+
type: route53.HealthCheckType.HTTP,
226+
fqdn: 'example.com',
227+
port: 80,
228+
resourcePath: '/health',
229+
failureThreshold: 3,
230+
requestInterval: Duration.seconds(30),
231+
});
232+
233+
new route53.ARecord(this, 'ARecordFailoverPrimary', {
234+
zone: myZone,
235+
target: route53.RecordTarget.fromIpAddresses('1.2.3.4'),
236+
failover: route53.Failover.PRIMARY,
237+
healthCheck,
238+
setIdentifier: 'failover-primary',
239+
});
240+
241+
new route53.ARecord(this, 'ARecordFailoverSecondary', {
242+
zone: myZone,
243+
target: route53.RecordTarget.fromIpAddresses('5.6.7.8'),
244+
failover: route53.Failover.SECONDARY,
245+
setIdentifier: 'failover-secondary',
246+
});
247+
```
248+
219249
To enable [multivalue answer routing](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-multivalue.html), use the `multivalueAnswer` parameter:
220250

221251
```ts

0 commit comments

Comments
 (0)