15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWSで全てのリージョンから無駄リソースを抽出するワンライナー

Last updated at Posted at 2015-04-08

ありがちな消去忘れなどを防ぐため、たまに以下のスクリプトを動かしてきれいな状態にしておきましょう。

  • aws configure は済ませてある前提です。まだの方はaws configureで設定するか、環境変数に設定するかを済ませて下さい。
    (2015/04/09 01:20 ELBに関する記述を変更しました)

EBS

for region in `aws ec2 describe-regions --query 'Regions[].RegionName' --output text`;do aws ec2 describe-volumes --region ${region} --filters Name=attachment.status,Values=detached;done

ElasticIP

for region in `aws ec2 describe-regions --query 'Regions[].RegionName' --output text`;do aws ec2 describe-addresses --region ${region} --query 'Addresses[?InstanceId==`null`]';done 

ELB

for region in `aws ec2 describe-regions --query 'Regions[].RegionName' --output text`;do aws elb describe-load-balancers --query 'LoadBalancerDescriptions[?length(Instances)==`0`].LoadBalancerName' --region ${region};done 

ENI

for region in `aws ec2 describe-regions --query 'Regions[].RegionName' --output text`;do aws ec2 describe-network-interfaces --filters Name=attachment.status,Values=detached --region ${region};done

参考

JMESpath
http://jmespath.readthedocs.org/en/latest/index.html

15
16
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?