Skip to content

modify_load_balancer_attributes

modify_load_balancer_attributes(
    *,
    config_overrides: Optional[ElasticLoadBalancingv2ClientConfig] = None,
    load_balancer_arn: Optional[LoadBalancerArn] = None,
    attributes: Optional[LoadBalancerAttributes] = None,
) -> ModifyLoadBalancerAttributesOutput

Modifies the specified attributes of the specified Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.

If any of the specified attributes can't be modified as requested, the call fails. Any existing attributes that you do not modify retain their current values.

Parameters:

Raises:

Examples:

To enable deletion protection This example enables deletion protection for the specified load balancer.

>>> client.modify_load_balancer_attributes(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', attributes=[{'Key': 'deletion_protection.enabled', 'Value': 'true'}])
To change the idle timeout
This example changes the idle timeout value for the specified load balancer.
>>> client.modify_load_balancer_attributes(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', attributes=[{'Key': 'idle_timeout.timeout_seconds', 'Value': '30'}])
To enable access logs
This example enables access logs for the specified load balancer. Note that the S3 bucket must exist in the same region as the load balancer and must have a policy attached that grants access to the Elastic Load Balancing service.
>>> client.modify_load_balancer_attributes(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', attributes=[{'Key': 'access_logs.s3.enabled', 'Value': 'true'}, {'Key': 'access_logs.s3.bucket', 'Value': 'my-loadbalancer-logs'}, {'Key': 'access_logs.s3.prefix', 'Value': 'myapp'}])
Source code in docs_src/capo_elastic_load_balancing_v2/_services/elastic_load_balancingv2.py
def modify_load_balancer_attributes(
    self,
    *,
    config_overrides: Optional[ElasticLoadBalancingv2ClientConfig] = None,
    load_balancer_arn: Optional[
        "capo_elastic_load_balancing_v2.types.load_balancer_arn.LoadBalancerArn"
    ] = None,
    attributes: Optional[
        "capo_elastic_load_balancing_v2.types.load_balancer_attributes.LoadBalancerAttributes"
    ] = None,
) -> "capo_elastic_load_balancing_v2.types.modify_load_balancer_attributes_output.ModifyLoadBalancerAttributesOutput":
    """<p>Modifies the specified attributes of the specified Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.</p> <p>If any of the specified attributes can't be modified as requested, the call fails. Any existing attributes that you do not modify retain their current values.</p>

    Args:
        load_balancer_arn: <p>The Amazon Resource Name (ARN) of the load balancer.</p>
        attributes: <p>The load balancer attributes.</p>

    Raises:
        capo_elastic_load_balancing_v2.errors.invalid_configuration_request_exception.InvalidConfigurationRequestException: <p>The requested configuration is not valid.</p>
        capo_elastic_load_balancing_v2.errors.load_balancer_not_found_exception.LoadBalancerNotFoundException: <p>The specified load balancer does not exist.</p>
        capo_elastic_load_balancing_v2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To enable deletion protection
        This example enables deletion protection for the specified load balancer.

        >>> client.modify_load_balancer_attributes(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', attributes=[{'Key': 'deletion_protection.enabled', 'Value': 'true'}])
        To change the idle timeout
        This example changes the idle timeout value for the specified load balancer.

        >>> client.modify_load_balancer_attributes(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', attributes=[{'Key': 'idle_timeout.timeout_seconds', 'Value': '30'}])
        To enable access logs
        This example enables access logs for the specified load balancer. Note that the S3 bucket must exist in the same region as the load balancer and must have a policy attached that grants access to the Elastic Load Balancing service.

        >>> client.modify_load_balancer_attributes(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', attributes=[{'Key': 'access_logs.s3.enabled', 'Value': 'true'}, {'Key': 'access_logs.s3.bucket', 'Value': 'my-loadbalancer-logs'}, {'Key': 'access_logs.s3.prefix', 'Value': 'myapp'}])
    """

    def _handler(
        req: "OperationRequest[capo_elastic_load_balancing_v2.types.modify_load_balancer_attributes_input.ModifyLoadBalancerAttributesInput]",
    ) -> OperationResponse[
        "capo_elastic_load_balancing_v2.types.modify_load_balancer_attributes_output.ModifyLoadBalancerAttributesOutput"
    ]:
        import capo_elastic_load_balancing_v2._operations.elastic_load_balancing_v10.modify_load_balancer_attributes

        output, http_response = (
            capo_elastic_load_balancing_v2._operations.elastic_load_balancing_v10.modify_load_balancer_attributes.modify_load_balancer_attributes(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ModifyLoadBalancerAttributes")
    )
    input_: capo_elastic_load_balancing_v2.types.modify_load_balancer_attributes_input.ModifyLoadBalancerAttributesInput = {}
    if load_balancer_arn is not None:
        input_["load_balancer_arn"] = load_balancer_arn
    if attributes is not None:
        input_["attributes"] = attributes

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