AMI 연결이 안되어있는 Snapshot 찾기 (Orphaned)

2022. 10. 13. 10:47기타/scripts

728x90
SMALL

- 개요

snapshot은 ec2를 삭제하거나 AMI를 삭제해도 같이 삭제되지 않으며 연결되어 있거나 사용중인지 확인 하는게 까다롭다. 또한 사용도 안되고 과금만 되고 있는 경우가 대부분이다. 아래는 AMI에 연결되어 있지 않는 snapshot을 확인하는 스크립트 이다.

 

 

- 스크립트

 

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)

 

- 참고

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

 

728x90
LIST