Skip to content

delete_db_instance async

delete_db_instance(
    *,
    config_overrides: Optional[AsyncRDSClientConfig] = None,
    db_instance_identifier: Optional[String] = None,
    skip_final_snapshot: Optional[Boolean] = None,
    final_db_snapshot_identifier: Optional[String] = None,
    delete_automated_backups: Optional[BooleanOptional] = None,
) -> DeleteDBInstanceResult

Deletes a previously provisioned DB instance. When you delete a DB instance, all automated backups for that instance are deleted and can't be recovered. However, manual DB snapshots of the DB instance aren't deleted.

If you request a final DB snapshot, the status of the Amazon RDS DB instance is deleting until the DB snapshot is created. This operation can't be canceled or reverted after it begins. To monitor the status of this operation, use DescribeDBInstance.

When a DB instance is in a failure state and has a status of failed, incompatible-restore, or incompatible-network, you can only delete it when you skip creation of the final snapshot with the SkipFinalSnapshot parameter.

If the specified DB instance is part of an Amazon Aurora DB cluster, you can't delete the DB instance if both of the following conditions are true:

  • The DB cluster is a read replica of another Amazon Aurora DB cluster.

  • The DB instance is the only instance in the DB cluster.

To delete a DB instance in this case, first use the PromoteReadReplicaDBCluster operation to promote the DB cluster so that it's no longer a read replica. After the promotion completes, use the DeleteDBInstance operation to delete the final instance in the DB cluster.

For RDS Custom DB instances, deleting the DB instance permanently deletes the EC2 instance and the associated EBS volumes. Make sure that you don't terminate or delete these resources before you delete the DB instance. Otherwise, deleting the DB instance and creation of the final snapshot might fail.

Parameters:

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

    The DB instance identifier for the DB instance to be deleted. This parameter isn't case-sensitive.

    Constraints:

    • Must match the name of an existing DB instance.

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

    Specifies whether to skip the creation of a final DB snapshot before deleting the instance. If you enable this parameter, RDS doesn't create a DB snapshot. If you don't enable this parameter, RDS creates a DB snapshot before the DB instance is deleted. By default, skip isn't enabled, and the DB snapshot is created.

    If you don't enable this parameter, you must specify the FinalDBSnapshotIdentifier parameter.

    When a DB instance is in a failure state and has a status of failed, incompatible-restore, or incompatible-network, RDS can delete the instance only if you enable this parameter.

    If you delete a read replica or an RDS Custom instance, you must enable this setting.

    This setting is required for RDS Custom.

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

    The DBSnapshotIdentifier of the new DBSnapshot created when the SkipFinalSnapshot parameter is disabled.

    If you enable this parameter and also enable SkipFinalShapshot, the command results in an error.

    This setting doesn't apply to RDS Custom.

    Constraints:

    • Must be 1 to 255 letters or numbers.

    • First character must be a letter.

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

    • Can't be specified when deleting a read replica.

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

    Specifies whether to remove automated backups immediately after the DB instance is deleted. This parameter isn't case-sensitive. The default is to remove automated backups immediately after the DB instance is deleted.

Raises:

Examples:

To delete a DB instance The following example deletes the specified DB instance after creating a final DB snapshot named test-instance-final-snap.

>>> await client.delete_db_instance(db_instance_identifier='test-instance', skip_final_snapshot=False, final_db_snapshot_identifier='test-instance-final-snap')
Source code in docs_src/capo_rds/_services/async_rds.py
async def delete_db_instance(
    self,
    *,
    config_overrides: Optional[AsyncRDSClientConfig] = None,
    db_instance_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,
) -> "capo_rds.types.delete_db_instance_result.DeleteDBInstanceResult":
    """<p>Deletes a previously provisioned DB instance. When you delete a DB instance, all automated backups for that instance are deleted and can't be recovered. However, manual DB snapshots of the DB instance aren't deleted.</p> <p>If you request a final DB snapshot, the status of the Amazon RDS DB instance is <code>deleting</code> until the DB snapshot is created. This operation can't be canceled or reverted after it begins. To monitor the status of this operation, use <code>DescribeDBInstance</code>.</p> <p>When a DB instance is in a failure state and has a status of <code>failed</code>, <code>incompatible-restore</code>, or <code>incompatible-network</code>, you can only delete it when you skip creation of the final snapshot with the <code>SkipFinalSnapshot</code> parameter.</p> <p>If the specified DB instance is part of an Amazon Aurora DB cluster, you can't delete the DB instance if both of the following conditions are true:</p> <ul> <li> <p>The DB cluster is a read replica of another Amazon Aurora DB cluster.</p> </li> <li> <p>The DB instance is the only instance in the DB cluster.</p> </li> </ul> <p>To delete a DB instance in this case, first use the <code>PromoteReadReplicaDBCluster</code> operation to promote the DB cluster so that it's no longer a read replica. After the promotion completes, use the <code>DeleteDBInstance</code> operation to delete the final instance in the DB cluster.</p> <important> <p>For RDS Custom DB instances, deleting the DB instance permanently deletes the EC2 instance and the associated EBS volumes. Make sure that you don't terminate or delete these resources before you delete the DB instance. Otherwise, deleting the DB instance and creation of the final snapshot might fail.</p> </important>

    Args:
        db_instance_identifier: <p>The DB instance identifier for the DB instance to be deleted. This parameter isn't case-sensitive.</p> <p>Constraints:</p> <ul> <li> <p>Must match the name of an existing DB instance.</p> </li> </ul>
        skip_final_snapshot: <p>Specifies whether to skip the creation of a final DB snapshot before deleting the instance. If you enable this parameter, RDS doesn't create a DB snapshot. If you don't enable this parameter, RDS creates a DB snapshot before the DB instance is deleted. By default, skip isn't enabled, and the DB snapshot is created.</p> <note> <p>If you don't enable this parameter, you must specify the <code>FinalDBSnapshotIdentifier</code> parameter.</p> </note> <p>When a DB instance is in a failure state and has a status of <code>failed</code>, <code>incompatible-restore</code>, or <code>incompatible-network</code>, RDS can delete the instance only if you enable this parameter.</p> <p>If you delete a read replica or an RDS Custom instance, you must enable this setting.</p> <p>This setting is required for RDS Custom.</p>
        final_db_snapshot_identifier: <p>The <code>DBSnapshotIdentifier</code> of the new <code>DBSnapshot</code> created when the <code>SkipFinalSnapshot</code> parameter is disabled.</p> <note> <p>If you enable this parameter and also enable SkipFinalShapshot, the command results in an error.</p> </note> <p>This setting doesn't apply to RDS Custom.</p> <p>Constraints:</p> <ul> <li> <p>Must be 1 to 255 letters or numbers.</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> <li> <p>Can't be specified when deleting a read replica.</p> </li> </ul>
        delete_automated_backups: <p>Specifies whether to remove automated backups immediately after the DB instance is deleted. This parameter isn't case-sensitive. The default is to remove automated backups immediately after the DB instance is deleted.</p>

    Raises:
        capo_rds.errors.db_instance_automated_backup_quota_exceeded_fault.DBInstanceAutomatedBackupQuotaExceededFault: <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 instance quota.</p>
        capo_rds.errors.db_instance_not_found_fault.DBInstanceNotFoundFault: <p> <code>DBInstanceIdentifier</code> doesn't refer to an existing DB instance.</p>
        capo_rds.errors.db_snapshot_already_exists_fault.DBSnapshotAlreadyExistsFault: <p> <code>DBSnapshotIdentifier</code> is already used by an existing snapshot.</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.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 instance
        The following example deletes the specified DB instance after creating a final DB snapshot named test-instance-final-snap.

        >>> await client.delete_db_instance(db_instance_identifier='test-instance', skip_final_snapshot=False, final_db_snapshot_identifier='test-instance-final-snap')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_rds.types.delete_db_instance_message.DeleteDBInstanceMessage]",
    ) -> AsyncOperationResponse[
        "capo_rds.types.delete_db_instance_result.DeleteDBInstanceResult"
    ]:
        import capo_rds._operations.amazon_rd_sv19.delete_db_instance

        (
            output,
            http_response,
        ) = await capo_rds._operations.amazon_rd_sv19.delete_db_instance.async_delete_db_instance(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

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

        return capo_rds.types.delete_db_instance_result.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("DeleteDBInstance", redact_output=_redact_output),
    )
    input_: capo_rds.types.delete_db_instance_message.DeleteDBInstanceMessage = {}
    if db_instance_identifier is not None:
        input_["db_instance_identifier"] = db_instance_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

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output