Skip to content

create_listener

create_listener(
    *,
    config_overrides: Optional[ElasticLoadBalancingv2ClientConfig] = None,
    load_balancer_arn: Optional[LoadBalancerArn] = None,
    protocol: Optional[ProtocolEnum] = None,
    port: Optional[Port] = None,
    ssl_policy: Optional[SslPolicyName] = None,
    certificates: Optional[CertificateList] = None,
    default_actions: Optional[Actions] = None,
    alpn_policy: Optional[AlpnPolicyName] = None,
    tags: Optional[TagList] = None,
    mutual_authentication: Optional[MutualAuthenticationAttributes] = None,
) -> CreateListenerOutput

Creates a listener for the specified Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.

For more information, see the following:

This operation is idempotent, which means that it completes at most one time. If you attempt to create multiple listeners with the same settings, each call succeeds.

Parameters:

  • load_balancer_arn (Optional[LoadBalancerArn], default: None ) –

    The Amazon Resource Name (ARN) of the load balancer.

  • protocol (Optional[ProtocolEnum], default: None ) –

    The protocol for connections from clients to the load balancer. For Application Load Balancers, the supported protocols are HTTP and HTTPS. For Network Load Balancers, the supported protocols are TCP, TLS, UDP, TCP_UDP, QUIC, and TCP_QUIC. You can’t specify the UDP, TCP_UDP, QUIC, or TCP_QUIC protocol if dual-stack mode is enabled. You can't specify a protocol for a Gateway Load Balancer.

  • port (Optional[Port], default: None ) –

    The port on which the load balancer is listening. You can't specify a port for a Gateway Load Balancer.

  • ssl_policy (Optional[SslPolicyName], default: None ) –

    [HTTPS and TLS listeners] The security policy that defines which protocols and ciphers are supported.

    For more information, see Security policies in the Application Load Balancers Guide and Security policies in the Network Load Balancers Guide.

  • certificates (Optional[CertificateList], default: None ) –

    [HTTPS and TLS listeners] The default certificate for the listener. You must provide exactly one certificate. Set CertificateArn to the certificate ARN but do not set IsDefault.

  • default_actions (Optional[Actions], default: None ) –

    The actions for the default rule.

  • alpn_policy (Optional[AlpnPolicyName], default: None ) –

    [TLS listeners] The name of the Application-Layer Protocol Negotiation (ALPN) policy. You can specify one policy name. The following are the possible values:

    • HTTP1Only

    • HTTP2Only

    • HTTP2Optional

    • HTTP2Preferred

    • None

    For more information, see ALPN policies in the Network Load Balancers Guide.

  • tags (Optional[TagList], default: None ) –

    The tags to assign to the listener.

  • mutual_authentication (Optional[MutualAuthenticationAttributes], default: None ) –

    [HTTPS listeners] The mutual authentication configuration information.

Raises:

Examples:

To create an HTTP listener This example creates an HTTP listener for the specified load balancer that forwards requests to the specified target group.

>>> client.create_listener(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', protocol='HTTP', port=80, default_actions=[{'Type': 'forward', 'TargetGroupArn': 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'}])
To create an HTTPS listener
This example creates an HTTPS listener for the specified load balancer that forwards requests to the specified target group. Note that you must specify an SSL certificate for an HTTPS listener. You can create and manage certificates using AWS Certificate Manager (ACM). Alternatively, you can create a certificate using SSL/TLS tools, get the certificate signed by a certificate authority (CA), and upload the certificate to AWS Identity and Access Management (IAM).
>>> client.create_listener(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', protocol='HTTPS', port=443, ssl_policy='ELBSecurityPolicy-2015-05', certificates=[{'CertificateArn': 'arn:aws:iam::123456789012:server-certificate/my-server-cert'}], default_actions=[{'Type': 'forward', 'TargetGroupArn': 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'}])
Source code in docs_src/capo_elastic_load_balancing_v2/_services/elastic_load_balancingv2.py
def create_listener(
    self,
    *,
    config_overrides: Optional[ElasticLoadBalancingv2ClientConfig] = None,
    load_balancer_arn: Optional[
        "capo_elastic_load_balancing_v2.types.load_balancer_arn.LoadBalancerArn"
    ] = None,
    protocol: Optional[
        "capo_elastic_load_balancing_v2.types.protocol_enum.ProtocolEnum"
    ] = None,
    port: Optional["capo_elastic_load_balancing_v2.types.port.Port"] = None,
    ssl_policy: Optional[
        "capo_elastic_load_balancing_v2.types.ssl_policy_name.SslPolicyName"
    ] = None,
    certificates: Optional[
        "capo_elastic_load_balancing_v2.types.certificate_list.CertificateList"
    ] = None,
    default_actions: Optional[
        "capo_elastic_load_balancing_v2.types.actions.Actions"
    ] = None,
    alpn_policy: Optional[
        "capo_elastic_load_balancing_v2.types.alpn_policy_name.AlpnPolicyName"
    ] = None,
    tags: Optional["capo_elastic_load_balancing_v2.types.tag_list.TagList"] = None,
    mutual_authentication: Optional[
        "capo_elastic_load_balancing_v2.types.mutual_authentication_attributes.MutualAuthenticationAttributes"
    ] = None,
) -> "capo_elastic_load_balancing_v2.types.create_listener_output.CreateListenerOutput":
    """<p>Creates a listener for the specified Application Load Balancer, Network Load Balancer, or Gateway Load Balancer.</p> <p>For more information, see the following:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html">Listeners for your Application Load Balancers</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-listeners.html">Listeners for your Network Load Balancers</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/gateway/gateway-listeners.html">Listeners for your Gateway Load Balancers</a> </p> </li> </ul> <p>This operation is idempotent, which means that it completes at most one time. If you attempt to create multiple listeners with the same settings, each call succeeds.</p>

    Args:
        load_balancer_arn: <p>The Amazon Resource Name (ARN) of the load balancer.</p>
        protocol: <p>The protocol for connections from clients to the load balancer. For Application Load Balancers, the supported protocols are HTTP and HTTPS. For Network Load Balancers, the supported protocols are TCP, TLS, UDP, TCP_UDP, QUIC, and TCP_QUIC. You can’t specify the UDP, TCP_UDP, QUIC, or TCP_QUIC protocol if dual-stack mode is enabled. You can't specify a protocol for a Gateway Load Balancer.</p>
        port: <p>The port on which the load balancer is listening. You can't specify a port for a Gateway Load Balancer.</p>
        ssl_policy: <p>[HTTPS and TLS listeners] The security policy that defines which protocols and ciphers are supported.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/describe-ssl-policies.html">Security policies</a> in the <i>Application Load Balancers Guide</i> and <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/describe-ssl-policies.html">Security policies</a> in the <i>Network Load Balancers Guide</i>.</p>
        certificates: <p>[HTTPS and TLS listeners] The default certificate for the listener. You must provide exactly one certificate. Set <code>CertificateArn</code> to the certificate ARN but do not set <code>IsDefault</code>.</p>
        default_actions: <p>The actions for the default rule.</p>
        alpn_policy: <p>[TLS listeners] The name of the Application-Layer Protocol Negotiation (ALPN) policy. You can specify one policy name. The following are the possible values:</p> <ul> <li> <p> <code>HTTP1Only</code> </p> </li> <li> <p> <code>HTTP2Only</code> </p> </li> <li> <p> <code>HTTP2Optional</code> </p> </li> <li> <p> <code>HTTP2Preferred</code> </p> </li> <li> <p> <code>None</code> </p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-listeners.html#alpn-policies">ALPN policies</a> in the <i>Network Load Balancers Guide</i>.</p>
        tags: <p>The tags to assign to the listener.</p>
        mutual_authentication: <p>[HTTPS listeners] The mutual authentication configuration information.</p>

    Raises:
        capo_elastic_load_balancing_v2.errors.alpn_policy_not_supported_exception.ALPNPolicyNotSupportedException: <p>The specified ALPN policy is not supported.</p>
        capo_elastic_load_balancing_v2.errors.certificate_not_found_exception.CertificateNotFoundException: <p>The specified certificate does not exist.</p>
        capo_elastic_load_balancing_v2.errors.duplicate_listener_exception.DuplicateListenerException: <p>A listener with the specified port already exists.</p>
        capo_elastic_load_balancing_v2.errors.incompatible_protocols_exception.IncompatibleProtocolsException: <p>The specified configuration is not valid with this protocol.</p>
        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.invalid_load_balancer_action_exception.InvalidLoadBalancerActionException: <p>The requested action 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.ssl_policy_not_found_exception.SSLPolicyNotFoundException: <p>The specified SSL policy does not exist.</p>
        capo_elastic_load_balancing_v2.errors.target_group_association_limit_exception.TargetGroupAssociationLimitException: <p>You've reached the limit on the number of load balancers per target group.</p>
        capo_elastic_load_balancing_v2.errors.target_group_not_found_exception.TargetGroupNotFoundException: <p>The specified target group does not exist.</p>
        capo_elastic_load_balancing_v2.errors.too_many_actions_exception.TooManyActionsException: <p>You've reached the limit on the number of actions per rule.</p>
        capo_elastic_load_balancing_v2.errors.too_many_certificates_exception.TooManyCertificatesException: <p>You've reached the limit on the number of certificates per load balancer.</p>
        capo_elastic_load_balancing_v2.errors.too_many_listeners_exception.TooManyListenersException: <p>You've reached the limit on the number of listeners per load balancer.</p>
        capo_elastic_load_balancing_v2.errors.too_many_registrations_for_target_id_exception.TooManyRegistrationsForTargetIdException: <p>You've reached the limit on the number of times a target can be registered with a load balancer.</p>
        capo_elastic_load_balancing_v2.errors.too_many_tags_exception.TooManyTagsException: <p>You've reached the limit on the number of tags for this resource.</p>
        capo_elastic_load_balancing_v2.errors.too_many_targets_exception.TooManyTargetsException: <p>You've reached the limit on the number of targets.</p>
        capo_elastic_load_balancing_v2.errors.too_many_unique_target_groups_per_load_balancer_exception.TooManyUniqueTargetGroupsPerLoadBalancerException: <p>You've reached the limit on the number of unique target groups per load balancer across all listeners. If a target group is used by multiple actions for a load balancer, it is counted as only one use.</p>
        capo_elastic_load_balancing_v2.errors.trust_store_not_found_exception.TrustStoreNotFoundException: <p>The specified trust store does not exist.</p>
        capo_elastic_load_balancing_v2.errors.trust_store_not_ready_exception.TrustStoreNotReadyException: <p>The specified trust store is not active.</p>
        capo_elastic_load_balancing_v2.errors.unsupported_protocol_exception.UnsupportedProtocolException: <p>The specified protocol is not supported.</p>
        capo_elastic_load_balancing_v2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create an HTTP listener
        This example creates an HTTP listener for the specified load balancer that forwards requests to the specified target group.

        >>> client.create_listener(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', protocol='HTTP', port=80, default_actions=[{'Type': 'forward', 'TargetGroupArn': 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'}])
        To create an HTTPS listener
        This example creates an HTTPS listener for the specified load balancer that forwards requests to the specified target group. Note that you must specify an SSL certificate for an HTTPS listener. You can create and manage certificates using AWS Certificate Manager (ACM). Alternatively, you can create a certificate using SSL/TLS tools, get the certificate signed by a certificate authority (CA), and upload the certificate to AWS Identity and Access Management (IAM).

        >>> client.create_listener(load_balancer_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188', protocol='HTTPS', port=443, ssl_policy='ELBSecurityPolicy-2015-05', certificates=[{'CertificateArn': 'arn:aws:iam::123456789012:server-certificate/my-server-cert'}], default_actions=[{'Type': 'forward', 'TargetGroupArn': 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'}])
    """

    def _handler(
        req: "OperationRequest[capo_elastic_load_balancing_v2.types.create_listener_input.CreateListenerInput]",
    ) -> OperationResponse[
        "capo_elastic_load_balancing_v2.types.create_listener_output.CreateListenerOutput"
    ]:
        import capo_elastic_load_balancing_v2._operations.elastic_load_balancing_v10.create_listener

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateListener")
    )
    input_: capo_elastic_load_balancing_v2.types.create_listener_input.CreateListenerInput = {}
    if load_balancer_arn is not None:
        input_["load_balancer_arn"] = load_balancer_arn
    if protocol is not None:
        input_["protocol"] = protocol
    if port is not None:
        input_["port"] = port
    if ssl_policy is not None:
        input_["ssl_policy"] = ssl_policy
    if certificates is not None:
        input_["certificates"] = certificates
    if default_actions is not None:
        input_["default_actions"] = default_actions
    if alpn_policy is not None:
        input_["alpn_policy"] = alpn_policy
    if tags is not None:
        input_["tags"] = tags
    if mutual_authentication is not None:
        input_["mutual_authentication"] = mutual_authentication

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