Help Center> Data Lake Insight> API Reference> Getting Started> Creating and Using a Datasource Connection

Creating and Using a Datasource Connection

Scenario Description

This section describes how to create an enhanced datasource connection using an API. For details on how to call APIs, see Calling APIs.

Constraints

  • It takes 6 to 10 minutes to start a job using a new queue for the first time.
  • Before creating an enhanced datasource connection, you need to obtain the ID of the VPC and the network ID of the subnet where the service is located. For details about the API used to obtain the VPC ID, see the Virtual Private Cloud API Reference. For details about the API used to obtain a subnet ID, see the Virtual Private Cloud API Reference.

Involved APIs

Procedure

  1. Create a queue. For details, see Creating a Queue. In the request, set resource_mode to 1 to create a dedicated queue.
  2. Create an enhanced datasource connection.
    • API

      URI format: POST /v2.0/{project_id}/datasource/enhanced-connections

    • Request example
      • Description: Create an enhanced datasource connection named test1 in project 48cc2c48765f481480c7db940d6409d1.
      • Example URL: POST https://{endpoint}/v2.0/48cc2c48765f481480c7db940d6409d1/datasource/enhanced-connections

        Obtain the endpoint from Regions and Endpoints.

      • Body:
        {
          "name": "test1",
          "dest_vpc_id": "22094d8f-c310-4621-913d-4c4d655d8495",
          "dest_network_id": "78f2562a-36e4-4b39-95b9-f5aab22e1281",
          "queues": ["q1","q2"],
          "hosts": [
            {
              "ip":"192.168.0.1",
              "name":"ecs-97f8-0001"
            },
            {
              "ip":"192.168.0.2", 
              "name":"ecs-97f8-0002"
            }
          ]
        }
    • Example response
      {
        "is_success": true,
        "message": "",
        "connection_id": "2a620c33-5609-40c9-affd-2b6453071b0f"
      }
  3. (Optional) If no queue is bound when you create an enhanced datasource connection, you can use the Binding a Queue API to bind a queue.
  4. Verify that the enhanced datasource connection is created successfully.
    • API

      URI format: GET /v2.0/{project_id}/datasource/enhanced-connections/{connection_id}

    • Request example
      • Description: Query an enhanced datasource connection whose ID is 2a620c33-5609-40c9-affd-2b6453071b0f in project 48cc2c48765f481480c7db940d6409d1.
      • Example URL: GET https://{endpoint}/v2.0/48cc2c48765f481480c7db940d6409d1/datasource/enhanced-connections/2a620c33-5609-40c9-affd-2b6453071b0f

        Obtain the endpoint from Regions and Endpoints.

      • Body:
        {}
    • Example response
      {
        "is_success": true,
        "message": "",
        "name": "test1",
        "id": "2a620c33-5609-40c9-affd-2b6453071b0f",
        "available_queue_info": [
          {
            "status": "ACTIVE",
            "name": "queue1",
            "peer_id": "2a620c33-5609-40c9-affd-2b6453071b0f",
            "err_msg": "",
            "update_time": 1566889577861
          }
        ],
        "dest_vpc_id": "22094d8f-c310-4621-913d-4c4d655d8495",
        "dest_network_id": "78f2562a-36e4-4b39-95b9-f5aab22e1281",
        "create_time": 1566888011125,
        "status": "ACTIVE",
        "hosts": [
          {
            "ip":"192.168.0.1",
            "name":"ecs-97f8-0001"
          },
          {
            "ip":"192.168.0.2", 
            "name":"ecs-97f8-0002"
          }
        ]
      }