Skip to content

delete_db_cluster

delete_db_cluster(
    *,
    config_overrides: Optional[RDSClientConfig] = None,
    db_cluster_identifier: Optional[String] = None,
    skip_final_snapshot: Optional[Boolean] = None,
    final_db_snapshot_identifier: Optional[String] = None,
    delete_automated_backups: Optional[BooleanOptional] = None,
    delete_db_instances: Optional[BooleanOptional] = None,
) -> DeleteDBClusterResult

The DeleteDBCluster action deletes a previously provisioned DB cluster. When you delete a DB cluster, all automated backups for that DB cluster are deleted and can't be recovered. Manual DB cluster snapshots of the specified DB cluster are not deleted.

If you're deleting a Multi-AZ DB cluster with read replicas, all cluster members are terminated and read replicas are promoted to standalone instances.

To delete an Amazon Aurora DB cluster and all of its DB instances in a single call, set DeleteDBInstances to true. Otherwise, delete each DB instance in the DB cluster before you delete the DB cluster.

For more information on Amazon Aurora, 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 DB cluster identifier for the DB cluster to be deleted. This parameter isn't case-sensitive.

    Constraints:

    • Must match an existing DBClusterIdentifier.

  • skip_final_snapshot (Optional[Boolean], default: None ) –

    Specifies whether to skip the creation of a final DB cluster snapshot before RDS deletes the DB cluster. If you set this value to true, RDS doesn't create a final DB cluster snapshot. If you set this value to false or don't specify it, RDS creates a DB cluster snapshot before it deletes the DB cluster. By default, this parameter is disabled, so RDS creates a final DB cluster snapshot.

    If SkipFinalSnapshot is disabled, you must specify a value for the FinalDBSnapshotIdentifier parameter.

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

    The DB cluster snapshot identifier of the new DB cluster snapshot created when SkipFinalSnapshot is disabled.

    If you specify this parameter and also skip the creation of a final DB cluster snapshot with the SkipFinalShapshot parameter, the request results in an error.

    Constraints:

    • Must be 1 to 255 letters, numbers, or hyphens.

    • First character must be a letter

    • Can't end with a hyphen or contain two consecutive hyphens

  • delete_automated_backups (Optional[BooleanOptional], default: None ) –

    Specifies whether to remove automated backups immediately after the DB cluster is deleted. This parameter isn't case-sensitive. The default is to remove automated backups immediately after the DB cluster is deleted, unless the Amazon Web Services Backup policy specifies a point-in-time restore rule.

  • delete_db_instances (Optional[BooleanOptional], default: None ) –

    Specifies whether to delete all DB instances in the DB cluster together with the DB cluster. If you set this value to true, RDS deletes every DB instance in the DB cluster and then deletes the DB cluster. You don't need to call DeleteDBInstance for each DB instance first. If you set this value to false or don't specify it, RDS deletes the DB cluster only after you delete each of its DB instances.

    You must have permission to call DeleteDBInstance on every DB instance in the DB cluster. If RDS can't delete a DB instance in the DB cluster, the request fails and RDS doesn't delete the DB cluster or any of its DB instances.

    Constraints:

    • You can't specify this parameter for a DB cluster that is a member of an Aurora global database. Remove the DB cluster from the global database first.

    • You can't specify this parameter for an Aurora Limitless Database DB cluster.

    • Deletion protection must be turned off for the DB cluster.

    • No DB instance in the DB cluster can be in the deleting state or be switching over, be the blue DB instance of an active blue/green deployment, or have an active zero-ETL integration.

    • No DB instance in the DB cluster can be the source of an Aurora read replica DB cluster, or have a read replica that is being created or a cross-Region read replica that is being restored.

    • The DB cluster can't be in the stopping state.

    If the DB cluster doesn't contain any DB instances, RDS deletes the DB cluster the same way as when you don't specify this parameter.

    Default: false

    Valid for Cluster Type: Aurora MySQL and Aurora PostgreSQL DB clusters only

Raises:

Examples:

To delete a DB cluster The following example deletes the DB cluster named mycluster and takes a final snapshot named mycluster-final-snapshot. The status of the DB cluster is available while the snapshot is being taken.

>>> client.delete_db_cluster(db_cluster_identifier='mycluster', skip_final_snapshot=False, final_db_snapshot_identifier='mycluster-final-snapshot')
To delete a DB cluster and all of its DB instances
The following example deletes the Aurora DB cluster named sample-cluster and all of the DB instances in it in a single call.
>>> client.delete_db_cluster(db_cluster_identifier='sample-cluster', delete_db_instances=True, skip_final_snapshot=True)
Source code in docs_src/capo_rds/_services/rds.py
def delete_db_cluster(
    self,
    *,
    config_overrides: Optional[RDSClientConfig] = None,
    db_cluster_identifier: Optional["capo_rds.types.string.String"] = None,
    skip_final_snapshot: Optional["capo_rds.types.boolean.Boolean"] = None,
    final_db_snapshot_identifier: Optional["capo_rds.types.string.String"] = None,
    delete_automated_backups: Optional[
        "capo_rds.types.boolean_optional.BooleanOptional"
    ] = None,
    delete_db_instances: Optional[
        "capo_rds.types.boolean_optional.BooleanOptional"
    ] = None,
) -> "capo_rds.types.delete_db_cluster_result.DeleteDBClusterResult":
    """<p>The DeleteDBCluster action deletes a previously provisioned DB cluster. When you delete a DB cluster, all automated backups for that DB cluster are deleted and can't be recovered. Manual DB cluster snapshots of the specified DB cluster are not deleted.</p> <p>If you're deleting a Multi-AZ DB cluster with read replicas, all cluster members are terminated and read replicas are promoted to standalone instances.</p> <p>To delete an Amazon Aurora DB cluster and all of its DB instances in a single call, set <code>DeleteDBInstances</code> to <code>true</code>. Otherwise, delete each DB instance in the DB cluster before you delete the DB cluster.</p> <p>For more information on Amazon Aurora, 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 DB cluster identifier for the DB cluster to be deleted. This parameter isn't case-sensitive.</p> <p>Constraints:</p> <ul> <li> <p>Must match an existing DBClusterIdentifier.</p> </li> </ul>
        skip_final_snapshot: <p>Specifies whether to skip the creation of a final DB cluster snapshot before RDS deletes the DB cluster. If you set this value to <code>true</code>, RDS doesn't create a final DB cluster snapshot. If you set this value to <code>false</code> or don't specify it, RDS creates a DB cluster snapshot before it deletes the DB cluster. By default, this parameter is disabled, so RDS creates a final DB cluster snapshot.</p> <note> <p>If <code>SkipFinalSnapshot</code> is disabled, you must specify a value for the <code>FinalDBSnapshotIdentifier</code> parameter.</p> </note>
        final_db_snapshot_identifier: <p>The DB cluster snapshot identifier of the new DB cluster snapshot created when <code>SkipFinalSnapshot</code> is disabled.</p> <note> <p>If you specify this parameter and also skip the creation of a final DB cluster snapshot with the <code>SkipFinalShapshot</code> parameter, the request results in an error.</p> </note> <p>Constraints:</p> <ul> <li> <p>Must be 1 to 255 letters, numbers, or hyphens.</p> </li> <li> <p>First character must be a letter</p> </li> <li> <p>Can't end with a hyphen or contain two consecutive hyphens</p> </li> </ul>
        delete_automated_backups: <p>Specifies whether to remove automated backups immediately after the DB cluster is deleted. This parameter isn't case-sensitive. The default is to remove automated backups immediately after the DB cluster is deleted, unless the Amazon Web Services Backup policy specifies a point-in-time restore rule.</p>
        delete_db_instances: <p>Specifies whether to delete all DB instances in the DB cluster together with the DB cluster. If you set this value to <code>true</code>, RDS deletes every DB instance in the DB cluster and then deletes the DB cluster. You don't need to call <code>DeleteDBInstance</code> for each DB instance first. If you set this value to <code>false</code> or don't specify it, RDS deletes the DB cluster only after you delete each of its DB instances.</p> <p>You must have permission to call <code>DeleteDBInstance</code> on every DB instance in the DB cluster. If RDS can't delete a DB instance in the DB cluster, the request fails and RDS doesn't delete the DB cluster or any of its DB instances.</p> <p>Constraints:</p> <ul> <li> <p>You can't specify this parameter for a DB cluster that is a member of an Aurora global database. Remove the DB cluster from the global database first.</p> </li> <li> <p>You can't specify this parameter for an Aurora Limitless Database DB cluster.</p> </li> <li> <p>Deletion protection must be turned off for the DB cluster.</p> </li> <li> <p>No DB instance in the DB cluster can be in the <code>deleting</code> state or be switching over, be the blue DB instance of an active blue/green deployment, or have an active zero-ETL integration.</p> </li> <li> <p>No DB instance in the DB cluster can be the source of an Aurora read replica DB cluster, or have a read replica that is being created or a cross-Region read replica that is being restored.</p> </li> <li> <p>The DB cluster can't be in the <code>stopping</code> state.</p> </li> </ul> <p>If the DB cluster doesn't contain any DB instances, RDS deletes the DB cluster the same way as when you don't specify this parameter.</p> <p>Default: <code>false</code> </p> <p>Valid for Cluster Type: Aurora MySQL and Aurora PostgreSQL DB clusters only</p>

    Raises:
        capo_rds.errors.db_cluster_automated_backup_quota_exceeded_fault.DBClusterAutomatedBackupQuotaExceededFault: <p>The quota for retained automated backups was exceeded. This prevents you from retaining any additional automated backups. The retained automated backups quota is the same as your DB cluster quota.</p>
        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.db_cluster_snapshot_already_exists_fault.DBClusterSnapshotAlreadyExistsFault: <p>The user already has a DB cluster snapshot with the given identifier.</p>
        capo_rds.errors.invalid_db_cluster_snapshot_state_fault.InvalidDBClusterSnapshotStateFault: <p>The supplied value isn't a valid DB cluster snapshot state.</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_global_cluster_state_fault.InvalidGlobalClusterStateFault: <p>The global cluster is in an invalid state and can't perform the requested operation.</p>
        capo_rds.errors.kms_key_not_accessible_fault.KMSKeyNotAccessibleFault: <p>An error occurred accessing an Amazon Web Services KMS key.</p>
        capo_rds.errors.snapshot_quota_exceeded_fault.SnapshotQuotaExceededFault: <p>The request would result in the user exceeding the allowed number of DB snapshots.</p>
        capo_rds.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To delete a DB cluster
        The following example deletes the DB cluster named mycluster and takes a final snapshot named mycluster-final-snapshot. The status of the DB cluster is available while the snapshot is being taken.

        >>> client.delete_db_cluster(db_cluster_identifier='mycluster', skip_final_snapshot=False, final_db_snapshot_identifier='mycluster-final-snapshot')
        To delete a DB cluster and all of its DB instances
        The following example deletes the Aurora DB cluster named sample-cluster and all of the DB instances in it in a single call.

        >>> client.delete_db_cluster(db_cluster_identifier='sample-cluster', delete_db_instances=True, skip_final_snapshot=True)
    """

    def _handler(
        req: "OperationRequest[capo_rds.types.delete_db_cluster_message.DeleteDBClusterMessage]",
    ) -> OperationResponse[
        "capo_rds.types.delete_db_cluster_result.DeleteDBClusterResult"
    ]:
        import capo_rds._operations.amazon_rd_sv19.delete_db_cluster

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

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

        return capo_rds.types.delete_db_cluster_result.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("DeleteDBCluster", redact_output=_redact_output),
    )
    input_: capo_rds.types.delete_db_cluster_message.DeleteDBClusterMessage = {}
    if db_cluster_identifier is not None:
        input_["db_cluster_identifier"] = db_cluster_identifier
    if skip_final_snapshot is not None:
        input_["skip_final_snapshot"] = skip_final_snapshot
    if final_db_snapshot_identifier is not None:
        input_["final_db_snapshot_identifier"] = final_db_snapshot_identifier
    if delete_automated_backups is not None:
        input_["delete_automated_backups"] = delete_automated_backups
    if delete_db_instances is not None:
        input_["delete_db_instances"] = delete_db_instances

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