Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify volume successfully created/attached in boto3?

I'm using boto3 client.create_volume and client.attach_volume APIs, but the return values are dictionaries, and the key State within the dictionary is creating for create_volume, and attaching for attach_volume. Is there any way to check if the volume is successfully created/attached within boto3?

like image 955
user284602 Avatar asked Jun 28 '17 15:06

user284602


2 Answers

Fortunately, boto3 has a concept called Waiters that can do the waiting for you!

See: EC2.Waiter.VolumeInUse

Polls EC2.Client.describe_volumes() every 15 seconds until a successful state is reached. An error is returned after 40 failed checks.

For those using ec2 client (ec2 = boto3.client('ec2')), you can do

ec2.get_waiter('volume_available').wait(VolumeIds=[new_volume['VolumeId']])

like image 129
John Rotenstein Avatar answered Oct 20 '22 02:10

John Rotenstein


See describe_volumes

Pass your volume_id and describe_volumes returns the information about:

Creation State:

'State': 'creating'|'available'|'in-use'|'deleting'|'deleted'|'error'

Attachment State:

'State': 'attaching'|'attached'|'detaching'|'detached'

and lot more information about your volume.

like image 21
helloV Avatar answered Oct 20 '22 02:10

helloV