Open4

よく使うかもしれないAWS CLI集

issyissy

aws/ec2

issyissy

セキュリティグループの一覧を表形式で出したい

JSONにしたい場合は--output jsonとする

 aws ec2 describe-security-groups --query 'SecurityGroups[*].{Name:GroupName,ID:GroupId,VPC:VpcId}' --output table
----------------------------------------------------------------------------------------------------------------------------------
|                                                     DescribeSecurityGroups                                                     |
+----------------------+-------------------------------------------------------------------------------+-------------------------+
|          ID          |                                     Name                                      |           VPC           |
+----------------------+-------------------------------------------------------------------------------+-------------------------+
|  sg-903004f8903004f8a|  xxxxxxxxxxxxx                                                                |  vpc-06e4ab6c6cEXAMPLE  |
|  sg-903004f8903004f8b|  xxxxxxxxxxxxxxxxxxxxxxxxxx                                                   |  vpc-06e4ab6c6cEXAMPLE  |
|  sg-903004f8903004f8c|  xxxxxxxxxxxxx                                                                |  vpc-06e4ab6c6cEXAMPLE  |
|  sg-903004f8903004f8d|  xxxxxxxxxxxxxxxxxxxxxxxxxx                                                   |  vpc-06e4ab6c6cEXAMPLE  |
|  sg-903004f8903004f8e|  default                                                                      |  vpc-06e4ab6c6cEXAMPLE  |

issyissy

指定したセキュリティグループのルールを表形式で出力したい。

JSONにしたい場合は--output jsonとする

aws ec2 describe-security-groups --query 'SecurityGroups[*].{Name:GroupName,ID:GroupId,IngressRules:IpPermissions}' --output table --group-ids  sg-0ca999999999999e9
------------------------------------------------------------------------------
|                           DescribeSecurityGroups                           |
+------------------------------+---------------------------------------------+
|              ID              |                    Name                     |
+------------------------------+---------------------------------------------+
|  sg-0ca999999999999e9        |  sg-name                                    |
+------------------------------+---------------------------------------------+
||                               IngressRules                               ||
|+-----------------------+-----------------------------+--------------------+|
||       FromPort        |         IpProtocol          |      ToPort        ||
|+-----------------------+-----------------------------+--------------------+|
||  0                    |  tcp                        |  65535             ||
|+-----------------------+-----------------------------+--------------------+|
|||                            UserIdGroupPairs                            |||
||+------------------------------+------------------------+----------------+||
|||          Description         |        GroupId         |    UserId      |||
||+------------------------------+------------------------+----------------+||
|||  Allow from xxxx             |  sg-0ca999999999999e9  |  123456789012  |||
|||  Allow from xxxx             |  sg-0ca999999999999e9  |  123456789012  |||
|||  Allow from xxxx             |  sg-0ca999999999999e9  |  123456789012  |||
||+------------------------------+------------------------+----------------+||
||                               IngressRules                               ||
|+-----------------------+-----------------------------+--------------------+|
||       FromPort        |         IpProtocol          |      ToPort        ||
|+-----------------------+-----------------------------+--------------------+|
||                       |  -1                         |                    ||
|+-----------------------+-----------------------------+--------------------+|
: