Created
October 14, 2025 22:42
-
-
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.
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
| #!/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