Skip to content

EC2  >  Operations  >  authorize_security_group_ingress

authorize_security_group_ingress

Operation

authorize_security_group_ingress async

authorize_security_group_ingress(request: AuthorizeSecurityGroupIngressInput | AuthorizeSecurityGroupIngressInputDict, /, *, plugins: list[Plugin] | None = None) -> AuthorizeSecurityGroupIngressOutput
authorize_security_group_ingress(*, plugins: list[Plugin] | None = None, **kwargs: Unpack[AuthorizeSecurityGroupIngressInputDict]) -> AuthorizeSecurityGroupIngressOutput

Adds the specified inbound (ingress) rules to a security group.

An inbound rule permits instances to receive traffic from the specified IPv4 or IPv6 address range, the IP address ranges that are specified by a prefix list, or the instances that are associated with a destination security group. For more information, see Security group rules.

You must specify exactly one of the following sources: an IPv4 or IPv6 address range, a prefix list, or a security group. You must specify a protocol for each rule (for example, TCP). If the protocol is TCP or UDP, you must also specify a port or port range. If the protocol is ICMP or ICMPv6, you must also specify the ICMP/ICMPv6 type and code.

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

For examples of rules that you can add to security groups for specific access scenarios, see Security group rules for different use cases in the Amazon EC2 User Guide.

For more information about security group quotas, see Amazon VPC quotas in the Amazon VPC User Guide.

Parameters:

Name Type Description Default
plugins list[Plugin] | None

A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations.

None

Returns:

Type Description
AuthorizeSecurityGroupIngressOutput

An instance of AuthorizeSecurityGroupIngressOutput.

Input

Pass the input fields as keyword arguments, or pass a model or dictionary as the first positional argument. Pass plugins separately as a keyword argument.

Model

AuthorizeSecurityGroupIngressInput dataclass

Bases: _SerdeShape

Dataclass for AuthorizeSecurityGroupIngressInput structure.

Attributes
cidr_ip class-attribute instance-attribute
cidr_ip: str | None = ...

The IPv4 address range, in CIDR format.

Note

Amazon Web Services canonicalizes IPv4 and IPv6 CIDRs. For example, if you specify 100.68.0.18/18 for the CIDR block, Amazon Web Services canonicalizes the CIDR block to 100.68.0.0/18. Any subsequent DescribeSecurityGroups and DescribeSecurityGroupRules calls will return the canonicalized form of the CIDR block. Additionally, if you attempt to add another rule with the non-canonical form of the CIDR (such as 100.68.0.18/18) and there is already a rule for the canonicalized form of the CIDR block (such as 100.68.0.0/18), the API throws an duplicate rule error.

To specify an IPv6 address range, use IP permissions instead.

To specify multiple rules and descriptions for the rules, use IP permissions instead.

dry_run class-attribute instance-attribute
dry_run: bool | None = ...

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.

from_port class-attribute instance-attribute
from_port: int | None = ...

If the protocol is TCP or UDP, this is the start of the port range. If the protocol is ICMP, this is the ICMP type or -1 (all ICMP types).

To specify multiple rules and descriptions for the rules, use IP permissions instead.

group_id class-attribute instance-attribute
group_id: str | None = ...

The ID of the security group.

group_name class-attribute instance-attribute
group_name: str | None = ...

[Default VPC] The name of the security group. For security groups for a default VPC you can specify either the ID or the name of the security group. For security groups for a nondefault VPC, you must specify the ID of the security group.

ip_permissions class-attribute instance-attribute
ip_permissions: list[IpPermission] | None = ...

The permissions for the security group rules.

ip_protocol class-attribute instance-attribute
ip_protocol: str | None = ...

The IP protocol name (tcp, udp, icmp) or number (see Protocol Numbers). To specify all protocols, use -1.

To specify icmpv6, use IP permissions instead.

If you specify a protocol other than one of the supported values, traffic is allowed on all ports, regardless of any ports that you specify.

To specify multiple rules and descriptions for the rules, use IP permissions instead.

source_security_group_name class-attribute instance-attribute
source_security_group_name: str | None = ...

[Default VPC] The name of the source security group.

The rule grants full ICMP, UDP, and TCP access. To create a rule with a specific protocol and port range, specify a set of IP permissions instead.

source_security_group_owner_id class-attribute instance-attribute
source_security_group_owner_id: str | None = ...

The Amazon Web Services account ID for the source security group, if the source security group is in a different account.

The rule grants full ICMP, UDP, and TCP access. To create a rule with a specific protocol and port range, use IP permissions instead.

tag_specifications class-attribute instance-attribute
tag_specifications: list[TagSpecification] | None = ...

The tags applied to the security group rule.

to_port class-attribute instance-attribute
to_port: int | None = ...

If the protocol is TCP or UDP, this is the end of the port range. If the protocol is ICMP, this is the ICMP code or -1 (all ICMP codes). If the start port is -1 (all ICMP types), then the end port must be -1 (all ICMP codes).

To specify multiple rules and descriptions for the rules, use IP permissions instead.

Dictionaries

AuthorizeSecurityGroupIngressInputDict

Bases: TypedDict

Dictionary form of AuthorizeSecurityGroupIngressInput.

Attributes
cidr_ip instance-attribute
cidr_ip: str | None

The IPv4 address range, in CIDR format.

Note

Amazon Web Services canonicalizes IPv4 and IPv6 CIDRs. For example, if you specify 100.68.0.18/18 for the CIDR block, Amazon Web Services canonicalizes the CIDR block to 100.68.0.0/18. Any subsequent DescribeSecurityGroups and DescribeSecurityGroupRules calls will return the canonicalized form of the CIDR block. Additionally, if you attempt to add another rule with the non-canonical form of the CIDR (such as 100.68.0.18/18) and there is already a rule for the canonicalized form of the CIDR block (such as 100.68.0.0/18), the API throws an duplicate rule error.

To specify an IPv6 address range, use IP permissions instead.

To specify multiple rules and descriptions for the rules, use IP permissions instead.

dry_run instance-attribute
dry_run: bool | None

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.

from_port instance-attribute
from_port: int | None

If the protocol is TCP or UDP, this is the start of the port range. If the protocol is ICMP, this is the ICMP type or -1 (all ICMP types).

To specify multiple rules and descriptions for the rules, use IP permissions instead.

group_id instance-attribute
group_id: str | None

The ID of the security group.

group_name instance-attribute
group_name: str | None

[Default VPC] The name of the security group. For security groups for a default VPC you can specify either the ID or the name of the security group. For security groups for a nondefault VPC, you must specify the ID of the security group.

ip_permissions instance-attribute
ip_permissions: Sequence[IpPermission | IpPermissionDict] | None

The permissions for the security group rules.

ip_protocol instance-attribute
ip_protocol: str | None

The IP protocol name (tcp, udp, icmp) or number (see Protocol Numbers). To specify all protocols, use -1.

To specify icmpv6, use IP permissions instead.

If you specify a protocol other than one of the supported values, traffic is allowed on all ports, regardless of any ports that you specify.

To specify multiple rules and descriptions for the rules, use IP permissions instead.

source_security_group_name instance-attribute
source_security_group_name: str | None

[Default VPC] The name of the source security group.

The rule grants full ICMP, UDP, and TCP access. To create a rule with a specific protocol and port range, specify a set of IP permissions instead.

source_security_group_owner_id instance-attribute
source_security_group_owner_id: str | None

The Amazon Web Services account ID for the source security group, if the source security group is in a different account.

The rule grants full ICMP, UDP, and TCP access. To create a rule with a specific protocol and port range, use IP permissions instead.

tag_specifications instance-attribute
tag_specifications: Sequence[TagSpecification | TagSpecificationDict] | None

The tags applied to the security group rule.

to_port instance-attribute
to_port: int | None

If the protocol is TCP or UDP, this is the end of the port range. If the protocol is ICMP, this is the ICMP code or -1 (all ICMP codes). If the start port is -1 (all ICMP types), then the end port must be -1 (all ICMP codes).

To specify multiple rules and descriptions for the rules, use IP permissions instead.

Output

AuthorizeSecurityGroupIngressOutput dataclass

Bases: _SerdeShape

Dataclass for AuthorizeSecurityGroupIngressOutput structure.

Attributes

response_metadata class-attribute instance-attribute
response_metadata: ResponseMetadata = ...

Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.

return_ class-attribute instance-attribute
return_: bool | None = ...

Returns true if the request succeeds; otherwise, returns an error.

security_group_rules class-attribute instance-attribute
security_group_rules: list[SecurityGroupRule] | None = ...

Information about the inbound (ingress) security group rules that were added.