AWS에서 미사용 EBS 한 번에 지우기

Autoscailing 사용시 instance 가 종료되면 ebs 가 남는 경우가 있는데,

정기적으로 지우기 위해서 조회해서 한번에 삭제하는 스크립트를 만들어 보았다.

AWS CLI 설치는 필수!

https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/cli-chap-install.html

미사용 볼륨 조회

aws ec2 describe-volumes --filters Name=status,Values=available

이런식으로 조회가 된다.

미사용 볼륨 삭제

aws ec2 delete-volume --volume-id [volume-id]

조회된 VolumeId를 넣어주면 된다.

CloudWatch 랑 람다 연동해서 삭제할 수도 있지만,

cloudwatch, 람다 비용 생각하면 개별로 job으로 지우는게 나을듯 하다.

(물론 얼마 안되긴 할꺼지만.)

미사용 볼륨 조회 및 삭제

aws ec2 describe-volumes --filters "Name=status,Values=available" | python3 -c "from __future__ import print_function; import json,sys; data=json.load(sys.stdin); [ print(v['VolumeId']) for v in data['Volumes']]" | xargs -n 1 -I % aws ec2 delete-volume --volume-id %

다시 조회하면 깨끗!

0 0 votes
Article Rating
Subscribe
Notify of
guest

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

0 Comments
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x
()
x