Search code examples
amazon-web-servicesaws-cloudformationaws-cliaws-security-group

How to describe Security Groups for a VPC?


Is there a way to describe a Security Group in a specific VPC?

Here is what I am trying to run :

aws ec2 describe-security-groups --group-name "<group-name>" --filter Name=vpc-id,Values=<my-vpc-id>

But it is returning this error :

A client error (VPCIdNotSpecified) occurred when calling the DescribeSecurityGroups operation: No default VPC for this user

I appreciate your help,

Thanks


Solution

  • To describe all security groups in a given VPC:

    aws ec2 describe-security-groups --filters "Name=vpc-id,Values=vpc-abcd1234"
    

    To describe a specific security group by its ID:

    aws ec2 describe-security-groups --group-id sg-1234abcd
    

    To describe a specific security group by its name (for non-default VPCs):

    aws ec2 describe-security-groups --filters Name=group-name,Values=MY-SG
    

    To describe a specific security group by its name and VPC (since there can be multiple groups with the same name in different VPCS):

    aws ec2 describe-security-groups --filters Name=group-name,Values=MY-SG Name=vpc-id,Values=vpc-abcd1234
    

    See AWS Command-Line Interface (CLI) documentation: describe-security-groups