Skip to content

delete_volume

delete_volume(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    volume_id: Optional[VolumeId] = None,
    dry_run: Optional[Boolean] = None,
) -> None

Deletes the specified EBS volume. The volume must be in the available state (not attached to an instance).

The volume can remain in the deleting state for several minutes.

For more information, see Delete an Amazon EBS volume in the Amazon EBS User Guide.

Parameters:

  • volume_id (Optional[VolumeId], default: None ) –

    The ID of the volume.

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

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Raises:

Examples:

To delete a volume This example deletes an available volume with the volume ID of vol-049df61146c4d7901. If the command succeeds, no output is returned.

>>> client.delete_volume(volume_id='vol-049df61146c4d7901')
Source code in docs_src/capo_ec2/_services/ec2.py
def delete_volume(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    volume_id: Optional["capo_ec2.types.volume_id.VolumeId"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> None:
    """<p>Deletes the specified EBS volume. The volume must be in the <code>available</code> state (not attached to an instance).</p> <p>The volume can remain in the <code>deleting</code> state for several minutes.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/ebs-deleting-volume.html">Delete an Amazon EBS volume</a> in the <i>Amazon EBS User Guide</i>.</p>

    Args:
        volume_id: <p>The ID of the volume.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To delete a volume
        This example deletes an available volume with the volume ID of ``vol-049df61146c4d7901``. If the command succeeds, no output is returned.

        >>> client.delete_volume(volume_id='vol-049df61146c4d7901')
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.delete_volume_request.DeleteVolumeRequest]",
    ) -> OperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.delete_volume

        output, http_response = (
            capo_ec2._operations.amazon_ec2.delete_volume.delete_volume(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeleteVolume")
    )
    input_: capo_ec2.types.delete_volume_request.DeleteVolumeRequest = {}
    if volume_id is not None:
        input_["volume_id"] = volume_id
    if dry_run is not None:
        input_["dry_run"] = dry_run

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