Skip to content

apply_security_groups_to_load_balancer

apply_security_groups_to_load_balancer(
    load_balancer_name: AccessPointName,
    security_groups: SecurityGroups,
    *,
    config_overrides: Optional[ElasticLoadBalancingClientConfig] = None,
) -> ApplySecurityGroupsToLoadBalancerOutput

Associates one or more security groups with your load balancer in a virtual private cloud (VPC). The specified security groups override the previously associated security groups.

For more information, see Security Groups for Load Balancers in a VPC in the Classic Load Balancers Guide.

Parameters:

  • load_balancer_name (AccessPointName) –

    The name of the load balancer.

  • security_groups (SecurityGroups) –

    The IDs of the security groups to associate with the load balancer. Note that you cannot specify the name of the security group.

Raises:

Examples:

To associate a security group with a load balancer in a VPC This example associates a security group with the specified load balancer in a VPC.

>>> client.apply_security_groups_to_load_balancer(load_balancer_name='my-load-balancer', security_groups=['sg-fc448899'])
Source code in docs_src/capo_elastic_load_balancing/_services/elastic_load_balancing.py
def apply_security_groups_to_load_balancer(
    self,
    load_balancer_name: "capo_elastic_load_balancing.types.access_point_name.AccessPointName",
    security_groups: "capo_elastic_load_balancing.types.security_groups.SecurityGroups",
    *,
    config_overrides: Optional[ElasticLoadBalancingClientConfig] = None,
) -> "capo_elastic_load_balancing.types.apply_security_groups_to_load_balancer_output.ApplySecurityGroupsToLoadBalancerOutput":
    """<p>Associates one or more security groups with your load balancer in a virtual private cloud (VPC). The specified security groups override the previously associated security groups.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-groups.html#elb-vpc-security-groups">Security Groups for Load Balancers in a VPC</a> in the <i>Classic Load Balancers Guide</i>.</p>

    Args:
        load_balancer_name: <p>The name of the load balancer.</p>
        security_groups: <p>The IDs of the security groups to associate with the load balancer. Note that you cannot specify the name of the security group.</p>

    Raises:
        capo_elastic_load_balancing.errors.access_point_not_found_exception.AccessPointNotFoundException: <p>The specified load balancer does not exist.</p>
        capo_elastic_load_balancing.errors.invalid_configuration_request_exception.InvalidConfigurationRequestException: <p>The requested configuration change is not valid.</p>
        capo_elastic_load_balancing.errors.invalid_security_group_exception.InvalidSecurityGroupException: <p>One or more of the specified security groups do not exist.</p>
        capo_elastic_load_balancing.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To associate a security group with a load balancer in a VPC
        This example associates a security group with the specified load balancer in a VPC.

        >>> client.apply_security_groups_to_load_balancer(load_balancer_name='my-load-balancer', security_groups=['sg-fc448899'])
    """

    def _handler(
        req: "OperationRequest[capo_elastic_load_balancing.types.apply_security_groups_to_load_balancer_input.ApplySecurityGroupsToLoadBalancerInput]",
    ) -> OperationResponse[
        "capo_elastic_load_balancing.types.apply_security_groups_to_load_balancer_output.ApplySecurityGroupsToLoadBalancerOutput"
    ]:
        import capo_elastic_load_balancing._operations.elastic_load_balancing_v7.apply_security_groups_to_load_balancer

        output, http_response = (
            capo_elastic_load_balancing._operations.elastic_load_balancing_v7.apply_security_groups_to_load_balancer.apply_security_groups_to_load_balancer(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ApplySecurityGroupsToLoadBalancer")
    )
    input_: capo_elastic_load_balancing.types.apply_security_groups_to_load_balancer_input.ApplySecurityGroupsToLoadBalancerInput = {
        "load_balancer_name": load_balancer_name,
        "security_groups": security_groups,
    }

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output