Skip to content

authorize_security_group_egress async

authorize_security_group_egress(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    dry_run: Optional[Boolean] = None,
    group_id: Optional[SecurityGroupId] = None,
    source_security_group_name: Optional[String] = None,
    source_security_group_owner_id: Optional[String] = None,
    ip_protocol: Optional[String] = None,
    from_port: Optional[Integer] = None,
    to_port: Optional[Integer] = None,
    cidr_ip: Optional[String] = None,
    ip_permissions: Optional[IpPermissionList] = None,
) -> AuthorizeSecurityGroupEgressResult

Adds the specified outbound (egress) rules to a security group.

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

You must specify exactly one of the following destinations: 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 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 information about security group quotas, see Amazon VPC quotas in the Amazon VPC User Guide.

Parameters:

  • 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 is UnauthorizedOperation.

  • group_id (Optional[SecurityGroupId], default: None ) –

    The ID of the security group.

  • source_security_group_name (Optional[String], default: None ) –

    Not supported. Use IP permissions instead.

  • source_security_group_owner_id (Optional[String], default: None ) –

    Not supported. Use IP permissions instead.

  • ip_protocol (Optional[String], default: None ) –

    Not supported. Use IP permissions instead.

  • from_port (Optional[Integer], default: None ) –

    Not supported. Use IP permissions instead.

  • to_port (Optional[Integer], default: None ) –

    Not supported. Use IP permissions instead.

  • cidr_ip (Optional[String], default: None ) –

    Not supported. Use IP permissions instead.

  • ip_permissions (Optional[IpPermissionList], default: None ) –

    The permissions for the security group rules.

Raises:

Examples:

To add a rule that allows outbound traffic to a specific address range This example adds a rule that grants access to the specified address ranges on TCP port 80.

>>> await client.authorize_security_group_egress(group_id='sg-1a2b3c4d', ip_permissions=[{'IpProtocol': 'tcp', 'FromPort': 80, 'ToPort': 80, 'IpRanges': [{'CidrIp': '10.0.0.0/16'}]}])
To add a rule that allows outbound traffic to a specific security group
This example adds a rule that grants access to the specified security group on TCP port 80.
>>> await client.authorize_security_group_egress(group_id='sg-1a2b3c4d', ip_permissions=[{'IpProtocol': 'tcp', 'FromPort': 80, 'ToPort': 80, 'UserIdGroupPairs': [{'GroupId': 'sg-4b51a32f'}]}])
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def authorize_security_group_egress(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    group_id: Optional["capo_ec2.types.security_group_id.SecurityGroupId"] = None,
    source_security_group_name: Optional["capo_ec2.types.string.String"] = None,
    source_security_group_owner_id: Optional["capo_ec2.types.string.String"] = None,
    ip_protocol: Optional["capo_ec2.types.string.String"] = None,
    from_port: Optional["capo_ec2.types.integer.Integer"] = None,
    to_port: Optional["capo_ec2.types.integer.Integer"] = None,
    cidr_ip: Optional["capo_ec2.types.string.String"] = None,
    ip_permissions: Optional[
        "capo_ec2.types.ip_permission_list.IpPermissionList"
    ] = None,
) -> "capo_ec2.types.authorize_security_group_egress_result.AuthorizeSecurityGroupEgressResult":
    """<p>Adds the specified outbound (egress) rules to a security group.</p> <p>An outbound rule permits instances to send traffic to the specified IPv4 or IPv6 address ranges, the IP address ranges specified by a prefix list, or the instances that are associated with a source security group. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/security-group-rules.html">Security group rules</a>.</p> <p>You must specify exactly one of the following destinations: 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 type and code.</p> <p>Rule changes are propagated to instances associated with the security group as quickly as possible. However, a small delay might occur.</p> <p>For examples of rules that you can add to security groups for specific access scenarios, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/security-group-rules-reference.html">Security group rules for different use cases</a> in the <i>Amazon EC2 User Guide</i>.</p> <p>For information about security group quotas, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/amazon-vpc-limits.html">Amazon VPC quotas</a> in the <i>Amazon VPC User Guide</i>.</p>

    Args:
        tag_specifications: <p>The tags applied to the security group rule.</p>
        dry_run: <p>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 <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        group_id: <p>The ID of the security group.</p>
        source_security_group_name: <p>Not supported. Use IP permissions instead.</p>
        source_security_group_owner_id: <p>Not supported. Use IP permissions instead.</p>
        ip_protocol: <p>Not supported. Use IP permissions instead.</p>
        from_port: <p>Not supported. Use IP permissions instead.</p>
        to_port: <p>Not supported. Use IP permissions instead.</p>
        cidr_ip: <p>Not supported. Use IP permissions instead.</p>
        ip_permissions: <p>The permissions for the security group rules.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To add a rule that allows outbound traffic to a specific address range
        This example adds a rule that grants access to the specified address ranges on TCP port 80.

        >>> await client.authorize_security_group_egress(group_id='sg-1a2b3c4d', ip_permissions=[{'IpProtocol': 'tcp', 'FromPort': 80, 'ToPort': 80, 'IpRanges': [{'CidrIp': '10.0.0.0/16'}]}])
        To add a rule that allows outbound traffic to a specific security group
        This example adds a rule that grants access to the specified security group on TCP port 80.

        >>> await client.authorize_security_group_egress(group_id='sg-1a2b3c4d', ip_permissions=[{'IpProtocol': 'tcp', 'FromPort': 80, 'ToPort': 80, 'UserIdGroupPairs': [{'GroupId': 'sg-4b51a32f'}]}])
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.authorize_security_group_egress_request.AuthorizeSecurityGroupEgressRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.authorize_security_group_egress_result.AuthorizeSecurityGroupEgressResult"
    ]:
        import capo_ec2._operations.amazon_ec2.authorize_security_group_egress

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.authorize_security_group_egress.async_authorize_security_group_egress(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AuthorizeSecurityGroupEgress")
    )
    input_: capo_ec2.types.authorize_security_group_egress_request.AuthorizeSecurityGroupEgressRequest = {}
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if group_id is not None:
        input_["group_id"] = group_id
    if source_security_group_name is not None:
        input_["source_security_group_name"] = source_security_group_name
    if source_security_group_owner_id is not None:
        input_["source_security_group_owner_id"] = source_security_group_owner_id
    if ip_protocol is not None:
        input_["ip_protocol"] = ip_protocol
    if from_port is not None:
        input_["from_port"] = from_port
    if to_port is not None:
        input_["to_port"] = to_port
    if cidr_ip is not None:
        input_["cidr_ip"] = cidr_ip
    if ip_permissions is not None:
        input_["ip_permissions"] = ip_permissions

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output