Last active
August 2, 2023 01:35
-
-
Save Kentzo/b8696d2e260b68ffc1782a97aa9aa844 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import botocore.waiter | |
import botocore.session | |
session = botocore.session.get_session() | |
client = session.create_client('ec2') | |
VOLUME_ID = ... # e.g. 'vol-049df61146c4d7901' | |
INSTANCE_ID = ... # e.g. 'i-1234567890abcdef0' | |
DEVICE = ... # e.g. '/dev/xvdba' | |
WAITER_ID = ... # e.g. 'MyWaiter' | |
model = botocore.waiter.WaiterModel({ | |
'version': 2, | |
'waiters': { | |
WAITER_ID: { | |
'delay': 15, | |
'operation': 'DescribeVolumes', | |
'maxAttempts': 40, | |
'acceptors': [ | |
{ | |
'expected': True, | |
'matcher': 'path', | |
'state': 'success', | |
'argument': "length(Volumes[?State == 'in-use'].Attachments[] | [?" | |
f"InstanceId == '{INSTANCE_ID}' &&" | |
f"Device == '{DEVICE}' &&" | |
"State == 'attached'" | |
"]) == `1`" | |
}, | |
{ | |
'expected': True, | |
'matcher': 'path', | |
'state': 'failure', | |
'argument': "length(Volumes[?State == 'in-use'].Attachments[] | [?" | |
f"InstanceId != '{INSTANCE_ID}' ||" | |
f"Device != '{DEVICE}'" | |
"]) > `0`" | |
}, | |
{ | |
'expected': 'deleted', | |
'matcher': 'pathAny', | |
'state': 'failure', | |
'argument': 'Volumes[].State' | |
}, | |
{ | |
'expected': 'error', | |
'matcher': 'pathAny', | |
'state': 'failure', | |
'argument': 'Volumes[].State' | |
} | |
] | |
} | |
} | |
}) | |
waiter = botocore.waiter.create_waiter_with_client(WAITER_ID, model, client) | |
waiter.wait(VolumeIds=[VOLUME_ID]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a note for anyone using this as an example line 15 "AndyCloudVolumeAttached" and line 55 "CustomVolumeAttached" need to be the same value, took me a little while of troubleshooting to figure this out