Skip to content

Instantly share code, notes, and snippets.

@Kazuma
Last active November 9, 2015 05:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kazuma/29b0ae677cf207e545a2 to your computer and use it in GitHub Desktop.
Save Kazuma/29b0ae677cf207e545a2 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# スナップショット一覧から AMI と紐付いていないスナップショットの ID を取得する
#
set -e
# Set environment
SNAPSHOT_LIST="snapshots.list"
IMAGE_LIST="images.list"
# Main
## AMI 一覧からスナップショット ID を取得
aws ec2 describe-images \
--owners self \
--query 'sort_by(Images[].BlockDeviceMappings[].Ebs[].{snapshot_id:SnapshotId},&snapshot_id)' \
--output text > $SNAPSHOT_LIST
## スナップショット一覧からスナップショット ID を取得
aws ec2 describe-snapshots \
--owner-ids self \
--filters Name="description",Values="Created*" \
--query 'sort_by(Snapshots[].{snapshot_id:SnapshotId},&snapshot_id)' \
--output text > $IMAGE_LIST
## AMI に紐付いていないスナップショット ID 一覧
diff ${SNAPSHOT_LIST} ${IMAGE_LIST} | sed -n 's:^> ::p'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment