メインコンテンツへスキップ

AWS CLIでセキュリティグループ一覧出力

    Cloud Formationでセキュリティグループをコード化するために、AWS CLIでセキュリティグループをJSONで出力してみました。
    JAWS-UG もくもく会で教えてもらって勉強になった。

    1.コマンド

    ・セキュリティグループIDでフィルタし、そのセキュリティグループのアウトバウンドをJSONで出力する

    aws ec2 describe-security-groups --output json  --query "SecurityGroups[?GroupId=='sg-xxx'].{GroupName:GroupName,IpPermissionsEgress:IpPermissionsEgress}" 

    ・セキュリティグループIDでフィルタし、そのセキュリティグループのインバウンドをJSONで出力する

    aws ec2 describe-security-groups --output json  --query "SecurityGroups[?GroupId=='sg-xxx'].{GroupName:GroupName,IpPermissions:IpPermissions}" 

    2.参考サイト

    https://blog.serverworks.co.jp/2021/12/08/174707
    https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html


    あなたへのおすすめ