Skip to content

Instantly share code, notes, and snippets.

@sgnn7
Last active December 17, 2020 15:17
Show Gist options
  • Save sgnn7/d27fb0ab6e2cb29d466198ced9ea93df to your computer and use it in GitHub Desktop.
Save sgnn7/d27fb0ab6e2cb29d466198ced9ea93df to your computer and use it in GitHub Desktop.

Revisions

  1. sgnn7 revised this gist Feb 27, 2017. No changes.
  2. sgnn7 created this gist Feb 27, 2017.
    39 changes: 39 additions & 0 deletions aws_ec2_wait.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/bin/bash -e

    EC2_REGION="us-west-1"
    DEFAULT_PROGRESS_WAIT=5

    # ========== SNAPSHOT WAIT ==============
    snapshot_id="snap-testtesttest"

    while [ "$snapshot_progress" != "100%" ]; do
    sleep "$DEFAULT_PROGRESS_WAIT"
    snapshot_progress=$(aws ec2 describe-snapshots --region $EC2_REGION \
    --snapshot-ids "$snapshot_id" \
    --no-paginate \
    --query "Snapshots[*].Progress" \
    --output text)
    echo "Snapshot progress: $snapshot_id $snapshot_progress"
    done

    aws ec2 wait snapshot-completed --region $EC2_REGION \
    --snapshot-ids "$snapshot_id"
    echo "- Snapshot done: $snapshot_id"

    # ========== VOLUME WAIT ==============
    new_volume_id="vol-testtesttest"

    while [ "$volume_status" != "available" ]; do
    sleep "$DEFAULT_PROGRESS_WAIT"
    volume_status=$(aws ec2 describe-volumes --region $EC2_REGION \
    --volume-ids "$new_volume_id" \
    --no-paginate \
    --query "Volumes[*].State" \
    --output text)
    echo "Volume progress: $new_volume_id $volume_status"
    done

    aws ec2 wait volume-available --region $EC2_REGION \
    --no-paginate \
    --volume-ids $new_volume_id
    echo "- Volume ready: $new_volume_id"