Help Center> Elastic Load Balance> API Reference> Examples> Add a Listener to a Shared Load Balancer

Add a Listener to a Shared Load Balancer

Scenarios

Call the API to add a listener.

Prerequisites

  • You have created a shared load balancer.
  • If you use a token for authentication, you must obtain the token and add X-Auth-Token to the request header of the ELB API when making a call. Obtain the token by following instructions in Authentication.

    The token obtained from IAM is valid for only 24 hours. If you want to use a token for authentication, you can cache it to avoid frequent calling.

Procedure

  1. Add a listener.
    1. Send POST https://{elb_endpoint}/v2/{project_id}/elb/listeners. project_id indicates the project ID.
    2. Add X-Auth-Token to the request header.
    3. Ensure that the following parameters are passed in the request body:
      {
          "listener":{
              "protocol_port":81, // Frontend port
              "protocol":"TCP", // Frontend protocol
              "loadbalancer_id":"0416b6f1-877f-4a51-987e-978b3f084253", // Load balancer to which the listener is to be added
              "name":"listener-test" //Listener name
          }
      }
    4. Check the response.
      • The request is successful if the following response is displayed:
        {
            "listener": {
                "insert_headers": {
                    "X-Forwarded-ELB-IP": true
                }, 
                "protocol_port": 81, 
                "protocol": "TCP", 
                "description": "", 
                "default_tls_container_ref": null, 
                "sni_container_refs": [ ], 
                "loadbalancers": [
                    {
                        "id": "0416b6f1-877f-4a51-987e-978b3f084253"
                    }
                ], 
                "tenant_id": "601240b9c5c94059b63d484c92cfe308", 
                "created_at": "2019-03-06T04:00:07", 
                "client_ca_tls_container_ref": null, 
                "connection_limit": -1, 
                "member_timeout": null,
                "client_timeout": null,
                "keepalive_timeout": 300,
                "updated_at": "2019-03-06T04:00:07", 
                "http2_enable": false, 
                "project_id": "601240b9c5c94059b63d484c92cfe308", 
                "admin_state_up": true, 
                "default_pool_id": null, 
                "id": "7f941f5c-80dc-43ac-8dfd-976fab49fa7a", 
                "tags": [ ], 
                "name": "listener-test"
            }
        }
      • If the request is abnormal, rectify the fault by referring to HTTP Status Codes of Shared Load Balancers.