Skip to content

Instantly share code, notes, and snippets.

@mattfield
Created July 19, 2017 09:56
Show Gist options
  • Save mattfield/c7fa990972989be93e31dac510c68ff7 to your computer and use it in GitHub Desktop.
Save mattfield/c7fa990972989be93e31dac510c68ff7 to your computer and use it in GitHub Desktop.
Bash snippet to poll attachment of EC2 volume
EC2_INSTANCE_ID=$(curl -s http://instance-data/latest/meta-data/instance-id)
DEVICE=/dev/sda
DATA_STATE="unknown"
until [ "$DATA_STATE" == "attached" ]; do
DATA_STATE=$(aws ec2 describe-volumes \
--region $REGION \
--filters \
Name=attachment.instance-id,Values=$EC2_INSTANCE_ID \
Name=attachment.device,Values=$DEVICE \
--query Volumes[].Attachments[].State \
--output text)
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment