AWS CLI + jq で AWS各サービスの一覧情報を取得する
みなさま, こんにちわ.
9月になっても, まだ日中は残暑のこってますねー. いかがお過ごしでしょうか?
最近の私というものも, めっきりAWSを触るようになってしまい, cliのコマンドを全く記憶できないのでメモることにしました笑
というのも, awsで色々構築していると, 全体像がよくわからないようになってしまうので, 定期的に一覧を取得して, 全体的な設計から外れたものがないかチェックするという目的があり, 用意しました.
jsonを整形してくれるjqコマンドは便利ですね!
環境
$ sw_vers ProductName: Mac OS X ProductVersion: 10.13.5 BuildVersion: 17F77 $ aws --version aws-cli/1.15.76 Python/2.7.15 Darwin/17.6.0 botocore/1.10.75 $ jq -V jq-1.5
※aws側のIAMなどの設定はこちらを参考にしました.(formatはjson.)
一覧取得コマンド
ec2
$ aws ec2 describe-instances --filter "Name=tag:Name,Values=*" | jq -r '.Reservations[].Instances[] | [.Tags[] | select(.Key == "Name").Value][] + "\t" + .InstanceId + "\t" + .PublicIpAddress + "\t" + .PrivateIpAddress + "\t" + .InstanceType + "\t" + .SubnetId + "\t" + .VpcId + "\t" + .ImageId + "\t" + .RootDeviceType + "\t" + .KeyName + "\t" + .Placement.AvailabilityZone' | sort
lb
$ aws elbv2 describe-load-balancers | jq -r '.LoadBalancers[] | .LoadBalancerName + "\t" + .DNSName + "\t" + .LoadBalancerArn + "\t" + .VpcId + "\t" + .IpAddressType + "\t" + .Type + "\t" + .Scheme + "\t" + .AvailabilityZones[].SubnetId + "\t" + .AvailabilityZones[].ZoneName' | sort
$ aws ec2 describe-vpcs| jq -r '.Vpcs[] | [.Tags[] | select(.Key == "Name").Value][] + "\t" + .VpcId + "\t" + .State + "\t" + .CidrBlock + "\t" + .DhcpOptionsId' | sort
subnets
$ aws ec2 describe-subnets | jq -r '.Subnets[] | [.Tags[] | select(.Key == "Name").Value][] + "\t" + .SubnetId + "\t" + .State + "\t" + .VpcId + "\t" + .AvailabilityZone + "\t" + .CidrBlock' | sort
適時アップデート予定...