detach_volume
¶
detach_volume(
*,
config_overrides: Optional[EC2ClientConfig] = None,
device: Optional[String] = None,
force: Optional[Boolean] = None,
instance_id: Optional[InstanceIdForResolver] = None,
volume_id: Optional[VolumeIdWithResolver] = None,
dry_run: Optional[Boolean] = None,
) -> VolumeAttachment
Detaches an EBS volume from an instance. Make sure to unmount any file systems on the device within your operating system before detaching the volume. Failure to do so can result in the volume becoming stuck in the busy state while detaching. If this happens, detachment can be delayed indefinitely until you unmount the volume, force detachment, reboot the instance, or all three. If an EBS volume is the root device of an instance, it can't be detached while the instance is running. To detach the root volume, stop the instance first.
When a volume with an Amazon Web Services Marketplace product code is detached from an instance, the product code is no longer associated with the instance.
You can't detach or force detach volumes that are attached to Amazon Web Services-managed resources. Attempting to do this results in the UnsupportedOperationException exception.
For more information, see Detach an Amazon EBS volume in the Amazon EBS User Guide.
Parameters:
-
device(Optional[String], default:None) –The device name.
-
force(Optional[Boolean], default:None) –Forces detachment if the previous detachment attempt did not occur cleanly (for example, logging into an instance, unmounting the volume, and detaching normally). This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance won't have an opportunity to flush file system caches or file system metadata. If you use this option, you must perform file system check and repair procedures.
-
instance_id(Optional[InstanceIdForResolver], default:None) –The ID of the instance. If you are detaching a Multi-Attach enabled volume, you must specify an instance ID.
-
volume_id(Optional[VolumeIdWithResolver], 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 isUnauthorizedOperation.
Raises:
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To detach a volume from an instance
This example detaches the volume (vol-049df61146c4d7901) from the instance it is attached to.
Source code in docs_src/capo_ec2/_services/ec2.py
38476 38477 38478 38479 38480 38481 38482 38483 38484 38485 38486 38487 38488 38489 38490 38491 38492 38493 38494 38495 38496 38497 38498 38499 38500 38501 38502 38503 38504 38505 38506 38507 38508 38509 38510 38511 38512 38513 38514 38515 38516 38517 38518 38519 38520 38521 38522 38523 38524 38525 38526 38527 38528 38529 38530 38531 38532 38533 38534 38535 38536 38537 38538 38539 38540 38541 38542 | |