Amazon Elastic Compute Cloud
API Reference (API Version 2011-12-15)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

AuthorizeSecurityGroupIngress

Description

Adds one or more ingress rules to a security group. This action applies to both EC2 security groups and VPC security groups. For information about VPC security groups and how they differ from EC2 security groups, go to Security Groups in the Amazon Virtual Private Cloud User Guide.

For EC2 security groups, this action gives one or more CIDR IP address ranges permission to access a security group in your account, or gives one or more security groups (called the source groups) permission to access a security group in your account. A source group can be in your own AWS account, or another.

For VPC security groups, this action gives one or more CIDR IP address ranges permission to access a security group in your VPC, or gives one or more other security groups (called the source groups) permission to access a security group in your VPC. The groups must all be in the same VPC.

Each rule consists of the protocol (e.g., TCP), plus either a CIDR range or a source group. For the TCP and UDP protocols, you must also specify the destination port or port range. For the ICMP protocol, you must also specify the ICMP type and code. You can use -1 for the type or code to mean all types or all codes.

Rule changes are propagated to instances within the security group as quickly as possible. However, a small delay might occur.

[Important]Important

For EC2 security groups: You can have up to 100 rules per group.

For VPC security groups: You can have up to 50 rules total per group (covering both ingress and egress).

Request Parameters

NameDescriptionRequired

UserId

Deprecated

No

GroupId

ID of the EC2 or VPC security group to modify. The group must belong to your account.

Type: String

Default: None

Condition: Required for VPC security groups; can be used instead of GroupName for EC2 security groups

Conditional

GroupName

Name of the EC2 security group to modify.

Type: String

Default: None

Condition: Can be used instead of GroupId for EC2 security groups

Conditional

IpPermissions.n.IpProtocol

IP protocol name or number (go to Protocol Numbers). EC2 security groups can have rules only for TCP, UDP, and ICMP, whereas VPC security groups can have rules assigned to any protocol number.

When you call DescribeSecurityGroups, the protocol value returned is the number. Exception: For TCP, UDP, and ICMP, the value returned is the name (e.g., tcp, udp, or icmp).

Type: String

Valid Values for EC2 security groups: tcp | udp | icmp or the corresponding protocol number (6 | 17 | 1).

Valid Values for VPC groups: tcp | udp | icmp or any protocol number (go to Protocol Numbers). Use -1 to specify all.

Required

IpPermissions.n.FromPort

Start of port range for the TCP and UDP protocols, or an ICMP type number. For the ICMP type number, you can use -1 to specify all ICMP types.

Type: Integer

Default: None

Default: Required for ICMP and any protocol that uses ports

Conditional

IpPermissions.n.ToPort

End of port range for the TCP and UDP protocols, or an ICMP code number. For the ICMP code number, you can use -1 to specify all ICMP codes for the given ICMP type.

Type: Integer

Default: None

Default: Required for ICMP and any protocol that uses ports

Conditional

IpPermissions.n.Groups.m.UserId

AWS account ID that owns the source security group. Cannot be used when specifying a CIDR IP address.

Type: String

Default: None

Condition: For EC2 security groups only. Required if modifying access for one or more source security groups.

Conditional

IpPermissions.n.Groups.m.GroupName

Name of the source security group. Cannot be used when specifying a CIDR IP address.

Type: String

Default: None

Condition: Required if modifying access for one or more source security groups.

Conditional

IpPermissions.n.Groups.m.GroupId

ID of the source security group. Cannot be used when specifying a CIDR IP address.

Type: String

Default: None

Condition: For VPC security groups only. Required if modifying access for one or more source security groups.

Conditional

IpPermissions.n.IpRanges.m.CidrIp

CIDR range. Cannot be used when specifying a source security group.

Type: String

Default: None

Constraints: Valid CIDR IP address range.

Condition: Required if modifying access for one or more IP address ranges.

Conditional

Response Elements

The elements in the following table are wrapped in an AuthorizeSecurityGroupIngressResponse structure.

NameDescription

requestId

The ID of the request.

Type: xsd:string

return

Returns true if request is successful. Otherwise, returns an error.

Type: xsd:boolean

Examples

Example Request

This example is for an EC2 security group. The request grants the 192.0.2.0/24 and 198.51.100.0/24 address ranges access to your websrv security group on TCP port 80.

https://ec2.amazonaws.com/?Action=AuthorizeSecurityGroupIngress
&GroupName=websrv
&IpPermissions.1.IpProtocol=tcp
&IpPermissions.1.FromPort=80
&IpPermissions.1.ToPort=80
&IpPermissions.1.IpRanges.1.CidrIp=192.0.2.0/24
&IpPermissions.1.IpRanges.2.CidrIp=198.51.100.0/24
&AUTHPARAMS

Example Request

This example is for an EC2 security group. The request grants TCP port 80 access from the source group called OtherAccountGroup (in AWS account 999988887777) to your websrv security group.

https://ec2.amazonaws.com/?Action=AuthorizeSecurityGroupIngress
&GroupName=websrv
&IpPermissions.1.IpProtocol=tcp
&IpPermissions.1.FromPort=80
&IpPermissions.1.ToPort=80
&IpPermissions.1.Groups.1.GroupName=OtherAccountGroup
&IpPermissions.1.Groups.1.UserId=999988887777
&AUTHPARAMS

Example Request

This example is for a VPC security group. The request grants TCP port 80 access from the source group called OtherGroupInMyVPC (sg-0a5d8e02) to your VpcWebServers security group (sg-140ba4c8). The request requires the group IDs and not the group names. Your AWS account ID is 111122223333.

https://ec2.amazonaws.com/?Action=AuthorizeSecurityGroupIngress
&GroupId=sg-140ba4c8
&IpPermissions.1.IpProtocol=tcp
&IpPermissions.1.FromPort=80
&IpPermissions.1.ToPort=80
&IpPermissions.1.Groups.1.GroupId=sg-0a5d8e02
&IpPermissions.1.Groups.1.UserId=111122223333
&AUTHPARAMS

Example Response

<AuthorizeSecurityGroupIngressResponse xmlns="http://ec2.amazonaws.com/doc/2011-12-15/">
  <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
  <return>true</return>
</AuthorizeSecurityGroupIngressResponse>