Skip to content

create_load_balancer_policy

create_load_balancer_policy(
    load_balancer_name: AccessPointName,
    policy_name: PolicyName,
    policy_type_name: PolicyTypeName,
    *,
    config_overrides: Optional[ElasticLoadBalancingClientConfig] = None,
    policy_attributes: Optional[PolicyAttributes] = None,
) -> CreateLoadBalancerPolicyOutput

Creates a policy with the specified attributes for the specified load balancer.

Policies are settings that are saved for your load balancer and that can be applied to the listener or the application server, depending on the policy type.

Parameters:

Raises:

Examples:

To create a policy that enables Proxy Protocol on a load balancer This example creates a policy that enables Proxy Protocol on the specified load balancer.

>>> client.create_load_balancer_policy(load_balancer_name='my-load-balancer', policy_name='my-ProxyProtocol-policy', policy_type_name='ProxyProtocolPolicyType', policy_attributes=[{'AttributeName': 'ProxyProtocol', 'AttributeValue': 'true'}])
To create a public key policy
This example creates a public key policy.
>>> client.create_load_balancer_policy(load_balancer_name='my-load-balancer', policy_name='my-PublicKey-policy', policy_type_name='PublicKeyPolicyType', policy_attributes=[{'AttributeName': 'PublicKey', 'AttributeValue': 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwAYUjnfyEyXr1pxjhFWBpMlggUcqoi3kl+dS74kj//c6x7ROtusUaeQCTgIUkayttRDWchuqo1pHC1u+n5xxXnBBe2ejbb2WRsKIQ5rXEeixsjFpFsojpSQKkzhVGI6mJVZBJDVKSHmswnwLBdofLhzvllpovBPTHe+o4haAWvDBALJU0pkSI1FecPHcs2hwxf14zHoXy1e2k36A64nXW43wtfx5qcVSIxtCEOjnYRg7RPvybaGfQ+v6Iaxb/+7J5kEvZhTFQId+bSiJImF1FSUT1W1xwzBZPUbcUkkXDj45vC2s3Z8E+Lk7a3uZhvsQHLZnrfuWjBWGWvZ/MhZYgEXAMPLE'}])
To create a backend server authentication policy
This example creates a backend server authentication policy that enables authentication on your backend instance using a public key policy.
>>> client.create_load_balancer_policy(load_balancer_name='my-load-balancer', policy_name='my-authentication-policy', policy_type_name='BackendServerAuthenticationPolicyType', policy_attributes=[{'AttributeName': 'PublicKeyPolicyName', 'AttributeValue': 'my-PublicKey-policy'}])
Source code in docs_src/capo_elastic_load_balancing/_services/elastic_load_balancing.py
def create_load_balancer_policy(
    self,
    load_balancer_name: "capo_elastic_load_balancing.types.access_point_name.AccessPointName",
    policy_name: "capo_elastic_load_balancing.types.policy_name.PolicyName",
    policy_type_name: "capo_elastic_load_balancing.types.policy_type_name.PolicyTypeName",
    *,
    config_overrides: Optional[ElasticLoadBalancingClientConfig] = None,
    policy_attributes: Optional[
        "capo_elastic_load_balancing.types.policy_attributes.PolicyAttributes"
    ] = None,
) -> "capo_elastic_load_balancing.types.create_load_balancer_policy_output.CreateLoadBalancerPolicyOutput":
    """<p>Creates a policy with the specified attributes for the specified load balancer.</p> <p>Policies are settings that are saved for your load balancer and that can be applied to the listener or the application server, depending on the policy type.</p>

    Args:
        load_balancer_name: <p>The name of the load balancer.</p>
        policy_name: <p>The name of the load balancer policy to be created. This name must be unique within the set of policies for this load balancer.</p>
        policy_type_name: <p>The name of the base policy type. To get the list of policy types, use <a>DescribeLoadBalancerPolicyTypes</a>.</p>
        policy_attributes: <p>The policy attributes.</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.duplicate_policy_name_exception.DuplicatePolicyNameException: <p>A policy with the specified name already exists for this load balancer.</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.policy_type_not_found_exception.PolicyTypeNotFoundException: <p>One or more of the specified policy types do not exist.</p>
        capo_elastic_load_balancing.errors.too_many_policies_exception.TooManyPoliciesException: <p>The quota for the number of policies for this load balancer has been reached.</p>
        capo_elastic_load_balancing.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create a policy that enables Proxy Protocol on a load balancer
        This example creates a policy that enables Proxy Protocol on the specified load balancer.

        >>> client.create_load_balancer_policy(load_balancer_name='my-load-balancer', policy_name='my-ProxyProtocol-policy', policy_type_name='ProxyProtocolPolicyType', policy_attributes=[{'AttributeName': 'ProxyProtocol', 'AttributeValue': 'true'}])
        To create a public key policy
        This example creates a public key policy.

        >>> client.create_load_balancer_policy(load_balancer_name='my-load-balancer', policy_name='my-PublicKey-policy', policy_type_name='PublicKeyPolicyType', policy_attributes=[{'AttributeName': 'PublicKey', 'AttributeValue': 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwAYUjnfyEyXr1pxjhFWBpMlggUcqoi3kl+dS74kj//c6x7ROtusUaeQCTgIUkayttRDWchuqo1pHC1u+n5xxXnBBe2ejbb2WRsKIQ5rXEeixsjFpFsojpSQKkzhVGI6mJVZBJDVKSHmswnwLBdofLhzvllpovBPTHe+o4haAWvDBALJU0pkSI1FecPHcs2hwxf14zHoXy1e2k36A64nXW43wtfx5qcVSIxtCEOjnYRg7RPvybaGfQ+v6Iaxb/+7J5kEvZhTFQId+bSiJImF1FSUT1W1xwzBZPUbcUkkXDj45vC2s3Z8E+Lk7a3uZhvsQHLZnrfuWjBWGWvZ/MhZYgEXAMPLE'}])
        To create a backend server authentication policy
        This example creates a backend server authentication policy that enables authentication on your backend instance using a public key policy.

        >>> client.create_load_balancer_policy(load_balancer_name='my-load-balancer', policy_name='my-authentication-policy', policy_type_name='BackendServerAuthenticationPolicyType', policy_attributes=[{'AttributeName': 'PublicKeyPolicyName', 'AttributeValue': 'my-PublicKey-policy'}])
    """

    def _handler(
        req: "OperationRequest[capo_elastic_load_balancing.types.create_load_balancer_policy_input.CreateLoadBalancerPolicyInput]",
    ) -> OperationResponse[
        "capo_elastic_load_balancing.types.create_load_balancer_policy_output.CreateLoadBalancerPolicyOutput"
    ]:
        import capo_elastic_load_balancing._operations.elastic_load_balancing_v7.create_load_balancer_policy

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateLoadBalancerPolicy")
    )
    input_: capo_elastic_load_balancing.types.create_load_balancer_policy_input.CreateLoadBalancerPolicyInput = {
        "load_balancer_name": load_balancer_name,
        "policy_name": policy_name,
        "policy_type_name": policy_type_name,
    }
    if policy_attributes is not None:
        input_["policy_attributes"] = policy_attributes

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