DescribeSecurityGroups - Amazon Elastic Compute Cloud

DescribeSecurityGroups

Describes the specified security groups or all of your security groups.

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

The 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.cidr - An IPv4 CIDR block for an outbound security group rule.

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

  • egress.ip-permission.group-id - The ID of a security group that has been referenced in an outbound security group rule.

  • egress.ip-permission.group-name - The name of a security group that is referenced in an outbound security group rule.

  • egress.ip-permission.ipv6-cidr - An IPv6 CIDR block for an outbound security group rule.

  • egress.ip-permission.prefix-list-id - The ID of a prefix list to which a security group rule allows outbound access.

  • egress.ip-permission.protocol - The IP protocol for an outbound security group rule (tcp | udp | icmp, a protocol number, or -1 for all protocols).

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

  • egress.ip-permission.user-id - The ID of an AWS account that has been referenced in an outbound security group rule.

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

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

  • ip-permission.cidr - An IPv4 CIDR block for an inbound security group rule.

  • ip-permission.from-port - For an inbound rule, 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 referenced in an inbound security group rule.

  • ip-permission.group-name - The name of a security group that is referenced in an inbound security group rule.

  • ip-permission.ipv6-cidr - An IPv6 CIDR block for an inbound security group rule.

  • ip-permission.prefix-list-id - The ID of a prefix list from which a security group rule allows inbound access.

  • ip-permission.protocol - The IP protocol for an inbound security group rule (tcp | udp | icmp, a protocol number, or -1 for all protocols).

  • ip-permission.to-port - For an inbound rule, 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 referenced in an inbound security group rule.

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

  • tag:<key> - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA, specify tag:Owner for the filter name and TeamA for the filter value.

  • tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.

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

Type: Array of Filter objects

Required: No

GroupId.N

The IDs of the security groups. Required for security groups in a nondefault VPC.

Default: Describes all of your security groups.

Type: Array of strings

Required: No

GroupName.N

[Default VPC] The names of the security groups. You can specify either the security group name or the security group ID.

Default: Describes all of your security groups.

Type: Array of strings

Required: No

MaxResults

The maximum number of items to return for this request. To get the next page of items, make another request with the token returned in the output. This value can be between 5 and 1000. If this parameter is not specified, then all items are returned. For more information, see Pagination.

Type: Integer

Valid Range: Minimum value of 5. Maximum value of 1000.

Required: No

NextToken

The token returned from a previous paginated request. Pagination continues from the end of the items returned by the previous request.

Type: String

Required: No

Response Elements

The following elements are returned by the service.

nextToken

The token to include in another request to get the next page of items. This value is null when there are no more items to return.

Type: String

requestId

The ID of the request.

Type: String

securityGroupInfo

Information about the security groups.

Type: Array of SecurityGroup objects

Errors

For information about the errors that are common to all actions, see Common client error codes.

Examples

Example 1

This example describes the specified security group. 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

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

Sample Response

<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> <securityGroupRuleId>sgr-abcdefghi01234560</securityGroupRuleId> <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 2

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

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 3

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

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

Sample Response

<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 4

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

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

Sample Response

<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: