Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Created October 14, 2025 22:42
Show Gist options
  • Select an option

  • Save gene1wood/a166f7605e7abcf8940d9bf0d7704e3c to your computer and use it in GitHub Desktop.

Select an option

Save gene1wood/a166f7605e7abcf8940d9bf0d7704e3c to your computer and use it in GitHub Desktop.
Attach all volumes in a given AWS availability zone to a single instance in that zone.
#!/bin/bash
ZONE=$1
INSTANCE_ID=$2
letter=b
for vol in $(aws ec2 describe-volumes --filters Name=status,Values=available Name=availability-zone,Values=$ZONE --query "Volumes[*].{ID:VolumeId}" --output text); do
aws ec2 attach-volume --volume-id $vol --instance-id $INSTANCE_ID --device /dev/sd${letter}
letter=$(echo "$letter" | tr "0-9a-z" "1-9a-z_")
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment