PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Attach and Detaching Volumes from Instances

Example 748. Attaching an EBS Volume

attachVolume will attach an EBS Volume to a running Instance. To attach a volume you need to specify the volumeId, the instanceId and the device (ex: /dev/sdh).

attachVolume will return an array with information about the attach status which contains volumeId, instanceId, device, status and attachTime

<?php
$ec2_ebs 
= new Zend_Service_Amazon_Ec2_Ebs('aws_key','aws_secret_key');
$return $ec2_ebs->attachVolume('volumeId''instanceid''/dev/sdh');

Example 749. Detaching an EBS Volume

detachVolume will detach an EBS Volume from a running Instance. detachVolume requires that you specify the volumeId with the optional instanceId and device name that was passed when attaching the volume. If you need to force the detachment you can set the fourth parameter to be TRUE and it will force the volume to detach.

detachVolume returns an array containing status information about the EBS Volume which includes volumeId, instanceId, device, status and attachTime.

<?php
$ec2_ebs 
= new Zend_Service_Amazon_Ec2_Ebs('aws_key','aws_secret_key');
$return $ec2_ebs->detachVolume('volumeId');

Forced Detach

You should only force a detach if the previous detachment attempt did not occur cleanly (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 will not have an opportunity to flush file system caches or file system meta data. If you use this option, you must perform file system check and repair procedures.

Zend Framework