authorize_security_group_ingress
async
¶
authorize_security_group_ingress(
*,
config_overrides: Optional[AsyncEC2ClientConfig] = None,
cidr_ip: Optional[String] = None,
from_port: Optional[Integer] = None,
group_id: Optional[SecurityGroupId] = None,
group_name: Optional[SecurityGroupName] = None,
ip_permissions: Optional[IpPermissionList] = None,
ip_protocol: Optional[String] = None,
source_security_group_name: Optional[String] = None,
source_security_group_owner_id: Optional[String] = None,
to_port: Optional[Integer] = None,
tag_specifications: Optional[TagSpecificationList] = None,
dry_run: Optional[Boolean] = None,
) -> AuthorizeSecurityGroupIngressResult
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:
-
cidr_ip(Optional[String], default:None) –The IPv4 address range, in CIDR format.
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.
-
from_port(Optional[Integer], default: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(Optional[SecurityGroupId], default:None) –The ID of the security group.
-
group_name(Optional[SecurityGroupName], default: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(Optional[IpPermissionList], default:None) –The permissions for the security group rules.
-
ip_protocol(Optional[String], default: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(Optional[String], default: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(Optional[String], default: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.
-
to_port(Optional[Integer], default: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.
-
tag_specifications(Optional[TagSpecificationList], default:None) –The tags applied to the security group rule.
-
dry_run(Optional[Boolean], default: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 isUnauthorizedOperation.
Raises:
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To add a rule that allows inbound HTTP traffic from another security group This example enables inbound traffic on TCP port 80 from the specified security group. The group must be in the same VPC or a peer VPC. Incoming traffic is allowed based on the private IP addresses of instances that are associated with the specified security group.
>>> await client.authorize_security_group_ingress(group_id='sg-111aaa22', ip_permissions=[{'IpProtocol': 'tcp', 'FromPort': 80, 'ToPort': 80, 'UserIdGroupPairs': [{'GroupId': 'sg-1a2b3c4d', 'Description': 'HTTP access from other instances'}]}])
To add a rule that allows inbound SSH traffic from an IPv4 address range
This example enables inbound traffic on TCP port 22 (SSH). The rule includes a description to help you identify it later.
>>> await client.authorize_security_group_ingress(group_id='sg-903004f8', ip_permissions=[{'IpProtocol': 'tcp', 'FromPort': 22, 'ToPort': 22, 'IpRanges': [{'CidrIp': '203.0.113.0/24', 'Description': 'SSH access from the LA office'}]}])
To add a rule that allows inbound RDP traffic from an IPv6 address range
This example adds an inbound rule that allows RDP traffic from the specified IPv6 address range. The rule includes a description to help you identify it later.
>>> await client.authorize_security_group_ingress(group_id='sg-123abc12 ', ip_permissions=[{'IpProtocol': 'tcp', 'FromPort': 3389, 'ToPort': 3389, 'Ipv6Ranges': [{'CidrIpv6': '2001:db8:1234:1a00::/64', 'Description': 'RDP access from the NY office'}]}])
Source code in docs_src/capo_ec2/_services/async_ec2.py
5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 | |