Skip to content

failover_db_cluster async

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

Forces a failover for a cluster.

A failover for a cluster promotes one of the Amazon DocumentDB replicas (read-only instances) in the cluster to be the primary instance (the cluster writer).

If the primary instance fails, Amazon DocumentDB automatically fails over to an Amazon DocumentDB replica, if one exists. You can force a failover when you want to simulate a failure of a primary instance for testing.

Parameters:

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

    A cluster identifier to force a failover for. This parameter is not case sensitive.

    Constraints:

    • Must match the identifier of an existing DBCluster.

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

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

    You must specify the instance identifier for an Amazon DocumentDB replica in the cluster. For example, mydbcluster-replica1.

Raises:

Source code in docs_src/capo_docdb/_services/async_doc_db.py
async def failover_db_cluster(
    self,
    *,
    config_overrides: Optional[AsyncDocDBClientConfig] = None,
    db_cluster_identifier: Optional["capo_docdb.types.string.String"] = None,
    target_db_instance_identifier: Optional[
        "capo_docdb.types.string.String"
    ] = None,
) -> "capo_docdb.types.failover_db_cluster_result.FailoverDBClusterResult":
    """<p>Forces a failover for a cluster.</p> <p>A failover for a cluster promotes one of the Amazon DocumentDB replicas (read-only instances) in the cluster to be the primary instance (the cluster writer).</p> <p>If the primary instance fails, Amazon DocumentDB automatically fails over to an Amazon DocumentDB replica, if one exists. You can force a failover when you want to simulate a failure of a primary instance for testing.</p>

    Args:
        db_cluster_identifier: <p>A cluster identifier to force a failover for. This parameter is not case sensitive.</p> <p>Constraints:</p> <ul> <li> <p>Must match the identifier of an existing <code>DBCluster</code>.</p> </li> </ul>
        target_db_instance_identifier: <p>The name of the instance to promote to the primary instance.</p> <p>You must specify the instance identifier for an Amazon DocumentDB replica in the cluster. For example, <code>mydbcluster-replica1</code>.</p>

    Raises:
        capo_docdb.errors.db_cluster_not_found_fault.DBClusterNotFoundFault: <p> <code>DBClusterIdentifier</code> doesn't refer to an existing cluster. </p>
        capo_docdb.errors.invalid_db_cluster_state_fault.InvalidDBClusterStateFault: <p>The cluster isn't in a valid state.</p>
        capo_docdb.errors.invalid_db_instance_state_fault.InvalidDBInstanceStateFault: <p> The specified instance isn't in the <i>available</i> state. </p>
        capo_docdb.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_docdb.types.failover_db_cluster_message.FailoverDBClusterMessage]",
    ) -> AsyncOperationResponse[
        "capo_docdb.types.failover_db_cluster_result.FailoverDBClusterResult"
    ]:
        import capo_docdb._operations.amazon_rd_sv19.failover_db_cluster

        (
            output,
            http_response,
        ) = await capo_docdb._operations.amazon_rd_sv19.failover_db_cluster.async_failover_db_cluster(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("FailoverDBCluster")
    )
    input_: capo_docdb.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 = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output