LoginSignup
4

More than 5 years have passed since last update.

[AWS] 特定のIPアドレスを含むセキュリティグループの一覧を表示する

Posted at

とある事情で AWS EC2 に設定されているセキュリティグループから
特定のIPアドレスを含む一覧を抜き出す必要がでてきたので
aws-cli で抜き出してみた

$ aws ec2 describe-security-groups \
 --filters Name=ip-permission.cidr,Values='xxx.xxx.xxx.xxx/32'
 --query 'SecurityGroups[*].{Name:GroupName, Description:Description}'

[
    {
        "Name": "hoge",
        "Description": "from hogehoge"
    },
     ...
]

CSV で欲しかったので jq に食わせる

$ aws ec2 describe-security-groups \ 
 --filters Name=ip-permission.cidr,Values='xxx.xxx.xxx.xxx/32' \
 --query 'SecurityGroups[*].{Name:GroupName, Description:Description}' | jq -r ".[] | [.Name, .Description] | @csv"

"hoge","from hogehoge"

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
4