AWS CLI to list AWS security groups

Get the list of security groups in the AWS account

Nov 13, 2022

Get the list of security groups in the AWS account

Prerequisites

AWS CLI command to list security groups

# filename: list-security-groups

aws ec2 describe-security-groups \
  --query 'SecurityGroups[*].{
    Name:GroupName,
    Id:GroupId,
    Vpc:VpcId}' \
  --output table

Sample output

--------------------------------------------------------------
|                   DescribeSecurityGroups                   |
+-----------------------+----------+-------------------------+
|          Id           |  Name    |           Vpc           |
+-----------------------+----------+-------------------------+
|  sg-0f18db46b549202de |  default |  vpc-01e4c55e6e91c5a85  |
|  sg-13fbac2a          |  default |  vpc-ac2ec5d1           |
+-----------------------+----------+-------------------------+

See also