orphaned and unused disk ec2 snapshots

etc/scripts

  • outline

Snapshots are not deleted even if you delete EC2 or AMI, and it is difficult to check whether they are connected or in use. Also, in most cases, it is not used and only charged for. Below is a script that checks for snapshots that are not connected to the AMI which means not using.

  • script
comm -23 <(aws ec2 --region $REGION describe-snapshots --owner-ids $AWS_ACCOUNT_ID --query Snapshots[*].SnapshotId --output text | tr '\t' '\n' | sort) <(aws ec2 --region $REGION describe-images --filters Name=state,Values=available --owners $AWS_ACCOUNT_ID --query "Images[*].BlockDeviceMappings[*].Ebs.SnapshotId" --output text | tr '\t' '\n' | sort)
  • reference

https://gist.github.com/daniilyar/45d3fc1867bf435d8c21e9e4864ff472