# Failover

The failover policy.

- Source: [`aws-route53/lib/record-set.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-route53/lib/record-set.ts#L176)
- Type last changed: v2.233.0 · 18 Dec 2025

## Example

TypeScript:

```ts
declare const myZone: route53.HostedZone;

const healthCheck = new route53.HealthCheck(this, 'HealthCheck', {
  type: route53.HealthCheckType.HTTP,
  fqdn: 'example.com',
  port: 80,
  resourcePath: '/health',
  failureThreshold: 3,
  requestInterval: Duration.seconds(30),
});

new route53.ARecord(this, 'ARecordFailoverPrimary', {
  zone: myZone,
  target: route53.RecordTarget.fromIpAddresses('1.2.3.4'),
  failover: route53.Failover.PRIMARY,
  healthCheck,
  setIdentifier: 'failover-primary',
});

new route53.ARecord(this, 'ARecordFailoverSecondary', {
  zone: myZone,
  target: route53.RecordTarget.fromIpAddresses('5.6.7.8'),
  failover: route53.Failover.SECONDARY,
  setIdentifier: 'failover-secondary',
});
```

Python:

```python
# my_zone: route53.HostedZone

health_check = route53.HealthCheck(self, "HealthCheck",
    type=route53.HealthCheckType.HTTP,
    fqdn="example.com",
    port=80,
    resource_path="/health",
    failure_threshold=3,
    request_interval=Duration.seconds(30)
)

route53.ARecord(self, "ARecordFailoverPrimary",
    zone=my_zone,
    target=route53.RecordTarget.from_ip_addresses("1.2.3.4"),
    failover=route53.Failover.PRIMARY,
    health_check=health_check,
    set_identifier="failover-primary"
)

route53.ARecord(self, "ARecordFailoverSecondary",
    zone=my_zone,
    target=route53.RecordTarget.from_ip_addresses("5.6.7.8"),
    failover=route53.Failover.SECONDARY,
    set_identifier="failover-secondary"
)
```

Java:

```java
HostedZone myZone;

HealthCheck healthCheck = HealthCheck.Builder.create(this, "HealthCheck")
        .type(HealthCheckType.HTTP)
        .fqdn("example.com")
        .port(80)
        .resourcePath("/health")
        .failureThreshold(3)
        .requestInterval(Duration.seconds(30))
        .build();

ARecord.Builder.create(this, "ARecordFailoverPrimary")
        .zone(myZone)
        .target(RecordTarget.fromIpAddresses("1.2.3.4"))
        .failover(Failover.PRIMARY)
        .healthCheck(healthCheck)
        .setIdentifier("failover-primary")
        .build();

ARecord.Builder.create(this, "ARecordFailoverSecondary")
        .zone(myZone)
        .target(RecordTarget.fromIpAddresses("5.6.7.8"))
        .failover(Failover.SECONDARY)
        .setIdentifier("failover-secondary")
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
HostedZone myZone;

var healthCheck = new HealthCheck(this, "HealthCheck", new HealthCheckProps {
    Type = HealthCheckType.HTTP,
    Fqdn = "example.com",
    Port = 80,
    ResourcePath = "/health",
    FailureThreshold = 3,
    RequestInterval = Duration.Seconds(30)
});

new ARecord(this, "ARecordFailoverPrimary", new ARecordProps {
    Zone = myZone,
    Target = RecordTarget.FromIpAddresses("1.2.3.4"),
    Failover = Failover.PRIMARY,
    HealthCheck = healthCheck,
    SetIdentifier = "failover-primary"
});

new ARecord(this, "ARecordFailoverSecondary", new ARecordProps {
    Zone = myZone,
    Target = RecordTarget.FromIpAddresses("5.6.7.8"),
    Failover = Failover.SECONDARY,
    SetIdentifier = "failover-secondary"
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var myZone HostedZone

healthCheck := route53.NewHealthCheck(this, jsii.String("HealthCheck"), &HealthCheckProps{
	Type: route53.HealthCheckType_HTTP,
	Fqdn: jsii.String("example.com"),
	Port: jsii.Number(80),
	ResourcePath: jsii.String("/health"),
	FailureThreshold: jsii.Number(3),
	RequestInterval: awscdk.Duration_Seconds(jsii.Number(30)),
})

route53.NewARecord(this, jsii.String("ARecordFailoverPrimary"), &ARecordProps{
	Zone: myZone,
	Target: route53.RecordTarget_FromIpAddresses(jsii.String("1.2.3.4")),
	Failover: route53.Failover_PRIMARY,
	HealthCheck: HealthCheck,
	SetIdentifier: jsii.String("failover-primary"),
})

route53.NewARecord(this, jsii.String("ARecordFailoverSecondary"), &ARecordProps{
	Zone: myZone,
	Target: route53.RecordTarget_*FromIpAddresses(jsii.String("5.6.7.8")),
	Failover: route53.Failover_SECONDARY,
	SetIdentifier: jsii.String("failover-secondary"),
})
```

## Members

| Member | Description |
| --- | --- |
| `PRIMARY` | The primary resource record set determines how Route 53 responds to DNS queries when the primary resource is healthy. |
| `SECONDARY` | The secondary resource record set determines how Route 53 responds to DNS queries when the primary resource is unhealthy. |

## Referenced by

- [`RecordSetOptions`](/v2/docs/aws-cdk-lib.aws_route53.RecordSetOptions).failover
