Menu
Amazon Elastic Compute Cloud
API Reference (API Version 2016-11-15)

DescribeSecurityGroups

Describes one or more of your security groups.

A security group is for use with instances either in the EC2-Classic platform or in a specific VPC. For more information, see Amazon EC2 Security Groups in the Amazon Elastic Compute Cloud User Guide and Security Groups for Your VPC in the Amazon Virtual Private Cloud User Guide.

Request Parameters

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

DryRun

Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Type: Boolean

Required: No

Filter.N

One or more filters. If using multiple filters for rules, the results include security groups for which any combination of rules - not necessarily a single rule - match all filters.

  • description - The description of the security group.

  • egress.ip-permission.prefix-list-id - The ID (prefix) of the AWS service to which the security group allows access.

  • group-id - The ID of the security group.

  • group-name - The name of the security group.

  • ip-permission.cidr - An IPv4 CIDR range that has been granted permission in a security group rule.

  • ip-permission.from-port - The start of port range for the TCP and UDP protocols, or an ICMP type number.

  • ip-permission.group-id - The ID of a security group that has been granted permission.

  • ip-permission.group-name - The name of a security group that has been granted permission.

  • ip-permission.ipv6-cidr - An IPv6 CIDR range that has been granted permission in a security group rule.

  • ip-permission.protocol - The IP protocol for the permission (tcp | udp | icmp or a protocol number).

  • ip-permission.to-port - The end of port range for the TCP and UDP protocols, or an ICMP code.

  • ip-permission.user-id - The ID of an AWS account that has been granted permission.

  • owner-id - The AWS account ID of the owner of the security group.

  • tag-key - The key of a tag assigned to the security group.

  • tag-value - The value of a tag assigned to the security group.

  • vpc-id - The ID of the VPC specified when the security group was created.

Type: Array of Filter objects

Required: No

GroupId.N

One or more security group IDs. Required for security groups in a nondefault VPC.

Default: Describes all your security groups.

Type: Array of strings

Required: No

GroupName.N

[EC2-Classic and default VPC only] One or more security group names. You can specify either the security group name or the security group ID. For security groups in a nondefault VPC, use the group-name filter to describe security groups by name.

Default: Describes all your security groups.

Type: Array of strings

Required: No

Response Elements

The following elements are returned by the service.

requestId

The ID of the request.

Type: String

securityGroupInfo

Information about one or more security groups.

Type: Array of SecurityGroup objects

Errors

For information about the errors that are common to all actions, see Common Errors.

Examples

Example 1

This example returns information about a security group named WebServers. Note that the GroupName parameter returns information about security groups in EC2-Classic or a default VPC only. If no security groups are found in either platform, an exception is returned, regardless of whether you have a security group with the specified name in a nondefault VPC.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=DescribeSecurityGroups &GroupName.1=WebServers &AUTHPARAMS

Sample Response

Copy
<DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> <securityGroupInfo> <item> <ownerId>123456789012</ownerId> <groupId>sg-1a2b3c4d</groupId> <groupName>WebServers</groupName> <groupDescription>Web Servers</groupDescription> <vpcId>vpc-614cc409</vpcId> <ipPermissions> <item> <ipProtocol>-1</ipProtocol> <groups> <item> <userId>123456789012</userId> <groupId>sg-af8661c0</groupId> </item> </groups> <ipRanges/> <prefixListIds/> </item> <item> <ipProtocol>tcp</ipProtocol> <fromPort>22</fromPort> <toPort>22</toPort> <groups/> <ipRanges> <item> <cidrIp>204.246.162.38/32</cidrIp> </item> </ipRanges> <prefixListIds/> </item> </ipPermissions> <ipPermissionsEgress> <item> <ipProtocol>-1</ipProtocol> <groups/> <ipRanges> <item> <cidrIp>0.0.0.0/0</cidrIp> </item> </ipRanges> <prefixListIds/> </item> </ipPermissionsEgress> </item> </securityGroupInfo> </DescribeSecurityGroupsResponse>

Example 2

[EC2-VPC] This example describes security group sg-1a2b3c4d. The response indicates that this security group references another security group. The referenced group can be in a different VPC if used through a VPC peering connection. If the referenced security group or the VPC peering connection is deleted, the rule becomes stale but is not automatically removed from the security group.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=DescribeSecurityGroups &GroupId.1=sg-1a2b3c4d &AUTHPARAMS

Sample Response

Copy
<DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>edb7c570-be05-4192-bd1b-example</requestId> <securityGroupInfo> <item> <ownerId>123456789012</ownerId> <groupId>sg-1a2b3c4d</groupId> <groupName>MySecurityGroup</groupName> <groupDescription>MySecurityGroup</groupDescription> <vpcId>vpc-81326ae4</vpcId> <ipPermissions> <item> <ipProtocol>tcp</ipProtocol> <fromPort>22</fromPort> <toPort>22</toPort> <groups/> <ipRanges> <item> <cidrIp>0.0.0.0/0</cidrIp> </item> </ipRanges> <prefixListIds/> </item> <item> <ipProtocol>icmp</ipProtocol> <fromPort>-1</fromPort> <toPort>-1</toPort> <groups> <item> <userId>111222333444</userId> <groupId>sg-11aa22bb</groupId> <vpcId>vpc-dd326ab8</vpcId> <vpcPeeringConnectionId>pcx-11223344</vpcPeeringConnectionId> <peeringStatus>active</peeringStatus> </item> </groups> <ipRanges/> <prefixListIds/> </item> </ipPermissions> <ipPermissionsEgress> <item> <ipProtocol>-1</ipProtocol> <groups/> <ipRanges> <item> <cidrIp>0.0.0.0/0</cidrIp> </item> </ipRanges> <prefixListIds/> </item> </ipPermissionsEgress> </item> </securityGroupInfo> </DescribeSecurityGroupsResponse>

Example 3

This example describes all security groups that grant access over port 22 and that grant access from instances associated with app_server_group or database_group.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=DescribeSecurityGroups &Filter.1.Name=ip-permission.protocol &Filter.1.Value.1=tcp &Filter.2.Name=ip-permission.from-port &Filter.2.Value.1=22 &Filter.3.Name=ip-permission.to-port &Filter.3.Value.1=22 &Filter.4.Name=ip-permission.group-name &Filter.4.Value.1=app_server_group &Filter.4.Value.2=database_group &AUTHPARAMS

Example 4

[EC2-VPC] This example describes the specified security group. The security group has a rule that allows all outbound IPv6 traffic (this rule is added by default for security groups in an IPv6-enabled VPC) and a rule that allows inbound access over SSH for IPv6 traffic.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=DescribeSecurityGroups &GroupId.1=sg-9bf6ceff &AUTHPARAMS

Sample Response

Copy
<DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>1d62eae0-acdd-481d-88c9-example</requestId> <securityGroupInfo> <item> <ownerId>123456789012</ownerId> <groupId>sg-9bf6ceff</groupId> <groupName>SSHAccess</groupName> <groupDescription>Security group for SSH access</groupDescription> <vpcId>vpc-31896b55</vpcId> <ipPermissions> <item> <ipProtocol>tcp</ipProtocol> <fromPort>22</fromPort> <toPort>22</toPort> <groups/> <ipRanges> <item> <cidrIp>0.0.0.0/0</cidrIp> </item> </ipRanges> <ipv6Ranges> <item> <cidrIpv6>::/0</cidrIpv6> </item> </ipv6Ranges> <prefixListIds/> </item> </ipPermissions> <ipPermissionsEgress> <item> <ipProtocol>-1</ipProtocol> <groups/> <ipRanges> <item> <cidrIp>0.0.0.0/0</cidrIp> </item> </ipRanges> <ipv6Ranges> <item> <cidrIpv6>::/0</cidrIpv6> </item> </ipv6Ranges> <prefixListIds/> </item> </ipPermissionsEgress> </item> </securityGroupInfo> </DescribeSecurityGroupsResponse>

Example 5

[EC2-VPC] This example describes the specified security group. For the ingress rule that permits RDP traffic from IPv4 address range 203.0.113.0/24, there is a rule description.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=DescribeSecurityGroups &GroupId.1=sg-bcc24bcd &AUTHPARAMS

Sample Response

Copy
<DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>6b0c76fb-0da6-4357-bb60-1fexample</requestId> <securityGroupInfo> <item> <ownerId>123456789012</ownerId> <groupId>sg-bcc24bcd</groupId> <groupName>default</groupName> <groupDescription>default VPC security group</groupDescription> <vpcId>vpc-a33cbfda</vpcId> <ipPermissions> <item> <ipProtocol>-1</ipProtocol> <groups> <item> <userId>123456789012</userId> <groupId>sg-bcc24bcd</groupId> </item> </groups> <ipRanges/> <ipv6Ranges/> <prefixListIds/> </item> <item> <ipProtocol>tcp</ipProtocol> <fromPort>3389</fromPort> <toPort>3389</toPort> <groups/> <ipRanges> <item> <cidrIp>203.0.113.0/24</cidrIp> <description>RDP access from B network</description> </item> </ipRanges> <ipv6Ranges/> <prefixListIds/> </item> </ipPermissions> <ipPermissionsEgress> <item> <ipProtocol>-1</ipProtocol> <groups/> <ipRanges> <item> <cidrIp>0.0.0.0/0</cidrIp> </item> </ipRanges> <ipv6Ranges/> <prefixListIds/> </item> </ipPermissionsEgress> </item> </securityGroupInfo> </DescribeSecurityGroupsResponse>

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: