Last active
November 9, 2015 05:43
-
-
Save Kazuma/29b0ae677cf207e545a2 to your computer and use it in GitHub Desktop.
This file contains 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/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