Skip to content

failover_db_cluster

failover_db_cluster(
    *,
    config_overrides: Optional[RDSClientConfig] = None,
    db_cluster_identifier: Optional[String] = None,
    target_db_instance_identifier: Optional[String] = None,
) -> FailoverDBClusterResult

Forces a failover for a DB cluster.

For an Aurora DB cluster, failover for a DB cluster promotes one of the Aurora Replicas (read-only instances) in the DB cluster to be the primary DB instance (the cluster writer).

For a Multi-AZ DB cluster, after RDS terminates the primary DB instance, the internal monitoring system detects that the primary DB instance is unhealthy and promotes a readable standby (read-only instances) in the DB cluster to be the primary DB instance (the cluster writer). Failover times are typically less than 35 seconds.

An Amazon Aurora DB cluster automatically fails over to an Aurora Replica, if one exists, when the primary DB instance fails. A Multi-AZ DB cluster automatically fails over to a readable standby DB instance when the primary DB instance fails.

To simulate a failure of a primary instance for testing, you can force a failover. Because each instance in a DB cluster has its own endpoint address, make sure to clean up and re-establish any existing connections that use those endpoint addresses when the failover is complete.

For more information on Amazon Aurora DB clusters, see What is Amazon Aurora? in the Amazon Aurora User Guide.

For more information on Multi-AZ DB clusters, see Multi-AZ DB cluster deployments in the Amazon RDS User Guide.

Parameters:

  • db_cluster_identifier (Optional[String], default: None ) –

    The identifier of the DB cluster to force a failover for. This parameter isn't case-sensitive.

    Constraints:

    • Must match the identifier of an existing DB cluster.

  • target_db_instance_identifier (Optional[String], default: None ) –

    The name of the DB instance to promote to the primary DB instance.

    Specify the DB instance identifier for an Aurora Replica or a Multi-AZ readable standby in the DB cluster, for example mydbcluster-replica1.

    This setting isn't supported for RDS for MySQL Multi-AZ DB clusters.

Raises:

Examples:

To perform a failover for a DB cluster This example performs a failover for the specified DB cluster to the specified DB instance.

>>> client.failover_db_cluster(db_cluster_identifier='myaurorainstance-cluster', target_db_instance_identifier='myaurorareplica')
Source code in docs_src/capo_rds/_services/rds.py
def failover_db_cluster(
    self,
    *,
    config_overrides: Optional[RDSClientConfig] = None,
    db_cluster_identifier: Optional["capo_rds.types.string.String"] = None,
    target_db_instance_identifier: Optional["capo_rds.types.string.String"] = None,
) -> "capo_rds.types.failover_db_cluster_result.FailoverDBClusterResult":
    """<p>Forces a failover for a DB cluster.</p> <p>For an Aurora DB cluster, failover for a DB cluster promotes one of the Aurora Replicas (read-only instances) in the DB cluster to be the primary DB instance (the cluster writer).</p> <p>For a Multi-AZ DB cluster, after RDS terminates the primary DB instance, the internal monitoring system detects that the primary DB instance is unhealthy and promotes a readable standby (read-only instances) in the DB cluster to be the primary DB instance (the cluster writer). Failover times are typically less than 35 seconds.</p> <p>An Amazon Aurora DB cluster automatically fails over to an Aurora Replica, if one exists, when the primary DB instance fails. A Multi-AZ DB cluster automatically fails over to a readable standby DB instance when the primary DB instance fails.</p> <p>To simulate a failure of a primary instance for testing, you can force a failover. Because each instance in a DB cluster has its own endpoint address, make sure to clean up and re-establish any existing connections that use those endpoint addresses when the failover is complete.</p> <p>For more information on Amazon Aurora DB clusters, see <a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html"> What is Amazon Aurora?</a> in the <i>Amazon Aurora User Guide</i>.</p> <p>For more information on Multi-AZ DB clusters, see <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/multi-az-db-clusters-concepts.html"> Multi-AZ DB cluster deployments</a> in the <i>Amazon RDS User Guide</i>.</p>

    Args:
        db_cluster_identifier: <p>The identifier of the DB cluster to force a failover for. This parameter isn't case-sensitive.</p> <p>Constraints:</p> <ul> <li> <p>Must match the identifier of an existing DB cluster.</p> </li> </ul>
        target_db_instance_identifier: <p>The name of the DB instance to promote to the primary DB instance.</p> <p>Specify the DB instance identifier for an Aurora Replica or a Multi-AZ readable standby in the DB cluster, for example <code>mydbcluster-replica1</code>.</p> <p>This setting isn't supported for RDS for MySQL Multi-AZ DB clusters.</p>

    Raises:
        capo_rds.errors.db_cluster_not_found_fault.DBClusterNotFoundFault: <p> <code>DBClusterIdentifier</code> doesn't refer to an existing DB cluster.</p>
        capo_rds.errors.invalid_db_cluster_state_fault.InvalidDBClusterStateFault: <p>The requested operation can't be performed while the cluster is in this state.</p>
        capo_rds.errors.invalid_db_instance_state_fault.InvalidDBInstanceStateFault: <p>The DB instance isn't in a valid state.</p>
        capo_rds.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To perform a failover for a DB cluster
        This example performs a failover for the specified DB cluster to the specified DB instance.

        >>> client.failover_db_cluster(db_cluster_identifier='myaurorainstance-cluster', target_db_instance_identifier='myaurorareplica')
    """

    def _handler(
        req: "OperationRequest[capo_rds.types.failover_db_cluster_message.FailoverDBClusterMessage]",
    ) -> OperationResponse[
        "capo_rds.types.failover_db_cluster_result.FailoverDBClusterResult"
    ]:
        import capo_rds._operations.amazon_rd_sv19.failover_db_cluster

        output, http_response = (
            capo_rds._operations.amazon_rd_sv19.failover_db_cluster.failover_db_cluster(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_output(
        output: "capo_rds.types.failover_db_cluster_result.FailoverDBClusterResult",
    ) -> dict[str, Any]:
        import capo_rds.types.failover_db_cluster_result

        return capo_rds.types.failover_db_cluster_result.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("FailoverDBCluster", redact_output=_redact_output),
    )
    input_: capo_rds.types.failover_db_cluster_message.FailoverDBClusterMessage = {}
    if db_cluster_identifier is not None:
        input_["db_cluster_identifier"] = db_cluster_identifier
    if target_db_instance_identifier is not None:
        input_["target_db_instance_identifier"] = target_db_instance_identifier

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output