sh awscli + jqで特定のVPCのプライベートIPを取得

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh awscli + jqで特定のVPCのプライベートIPを取得相关的知识,希望对你有一定的参考价值。

 aws ec2 describe-instances --region ap-northeast-1 | jq '.Reservations[].Instances[] | select(.State.Name == "running") |.NetworkInterfaces[0] | select(.VpcId == "vpc-VPCID") | .PrivateIpAddress'
 
 # Nameが空のもののみ
aws ec2 describe-instances --region ap-northeast-1 | jq '.Reservations[].Instances[] | select(.State.Name == "running") | select(.Tags == null or .Tags[].Key == null or .Tags[].Key == "Name" and .Tags[].Value == "")| .NetworkInterfaces[0] | select(.VpcId == "vpc-VPC") | .PrivateIpAddress' 

# 生きているインスタンスのName, localIP (VPC指定)
$ aws ec2 describe-instances --region ap-northeast-1 | jq -r '.Reservations[].Instances[] | select(.State.Name == "running") | select(.NetworkInterfaces[0].VpcId == "vpc-VPC") | [(if .Tags != null then (.Tags[] |select(.Key == "Name").Value) else null end), .NetworkInterfaces[0].PrivateIpAddress]| @csv'

以上是关于sh awscli + jqで特定のVPCのプライベートIPを取得的主要内容,如果未能解决你的问题,请参考以下文章