Access an instance over HTTPS

Updated at:
Copy as MD

This topic shows you how to access an instance over HTTPS by using the secure access proxy.

Prerequisites

  • The secure access proxy is enabled for the instance.

    Note

    You can view instances with the secure access proxy enabled on the Created tab of the Security and Specifications > Secure Access Proxy page. To enable this feature, see Enable the secure access proxy.

  • You are authorized to use the secure access proxy.

    Note

    Check your authorization status for the instance on the details page of the secure access proxy. If you are not authorized, see Apply for secure access proxy authorization.

Usage notes

Security rules apply to instances that have both the secure access proxy and secure collaboration features enabled. We recommend that you limit a single query to return a maximum of 3,000 rows. Data Management Service (DMS) cannot guarantee stability if a query returns too many rows.

Note
  • To avoid security rule limits, use the endpoint in the DMS console to access the database, or contact DMS technical support to evaluate your specific scenario.

  • For instances that do not use the secure collaboration feature, you cannot configure the maximum number of rows to return. The default limit is 3,000 rows.

Request parameters

Parameter

Description

Required

Method

accessId

The AccessKey ID.

Yes

You can pass this parameter in one of the following ways:

  • As a query parameter.

    Example: ?accessId=<YOUR_ACCESSKEY_ID>

  • As a header parameter.

    Example: accessId: <YOUR_ACCESSKEY_ID>

accessSecret

The AccessKey Secret.

Yes

You can pass this parameter in one of the following ways:

  • As a query parameter.

    Example: ?accessSecret=<YOUR_ACCESSKEY_SECRET>

  • As a header parameter.

    Example: accessSecret: <YOUR_ACCESSKEY_SECRET>

schema

The database name.

No

You can pass this parameter in one of the following ways:

  • As a URL path parameter.

    Example: /server/<YOUR_DATABASE_NAME>

  • As a body parameter.

    Example: { "schema": "<YOUR_DATABASE_NAME>" }

sql

The SQL statement to execute.

Yes

You can pass this parameter in one of the following ways:

  • As a URL parameter.

  • As a body parameter.

    Plain text format: <YOUR_SQL_STATEMENT>

    JSON format: { "sql": "<YOUR_SQL_STATEMENT>" }

Response format

When you access the instance over HTTPS, the response is returned in JSON format.

The JSON object has the following structure:

Field

Type

Description

columnMetas

Array

A list of metadata for the columns.

columnName

String

The column name.

columnLabel

String

The column label, which corresponds to the alias specified after AS in the SQL statement. If no alias is used, this value is the same as columnName.

columnTypeName

String

The data type of the column, such as VARCHAR or BIGINT.

precision

Integer

The precision for certain data types. For example, for VARCHAR(32), the precision is 32.

scale

Integer

The scale for floating-point data types, which indicates the number of digits after the decimal point. For example, for DECIMAL(10,2), the scale is 2.

nullable

Boolean

Indicates whether the column can contain null values. true means it can be null, and false means it cannot.

autoIncrement

Boolean

Indicates whether the column is auto-incrementing. true means it is an auto-incrementing column, and false means it is not.

tableName

String

The name of the table that contains the column.

msg

String

The error message returned if the request fails.

updateCount

Integer

The number of records affected by a Data Manipulation Language (DML) statement.

requestId

String

The request ID. Use this ID for troubleshooting if you encounter an issue.

rowCount

Integer

The number of records returned by a query.

rows

Array

A list of records returned by a query. Each element in the array represents a row of data, similar to a List<Map> structure.

success

Boolean

Indicates whether the request was successful. true means success, and false means failure.

The following are sample responses:

  • Successful query

    {
      "columnMetas": [
        {
          "columnName":"column1",
          "columnLabel":"column1",
          "columnTypeName":"varchar",
          "precision":10,
          "scale":2,
          "nullable":true,
          "autoIncrement":true,
          "tableName":"table1"
        },
        {
          "columnName":"column2",
          "columnLabel":"column2",
          "columnTypeName":"varchar",
          "precision":10,
          "scale":2,
          "nullable":true,
          "autoIncrement":true,
          "tableName":"table1"
        } 
      ],
      "updateCount": 0,
      "requestId": "xhqej0xgcytbhc8scjopgqsywcaibi",
      "rowCount": 1,
      "rows": [
        {
          "col1": 1,
          "col2": "xxxx"
        }
      ],
      "success": true
    }
  • Successful update

    {
      "updateCount": 0,
      "requestId": "xhqej0xgcytbhc8scjopgqsywcaibi",
      "success": true
    }
  • Request failure

    {
      "message": 'AccessKey ID is required.',
      "requestId": "xhqej0xgcytbhc8scjopgqsywcaibi",
      "success": false
    }

Examples

You can use the command line, an SQL client, or application code to access an instance that has the secure access proxy enabled.

The following examples use these values: the endpoint is dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com, the database name is database, the AccessKey ID is user, the AccessKey Secret is pwd, and the SQL command is SHOW DATABASES.

  • Use the curl command

    # GET request
    curl 'https:///server/?accessId=&accessSecret=&sql='
    # GET request example
    curl 'https://dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com/server/database?accessId=user&accessSecret=pwd&sql=SHOW%20DATABASES'
    # POST request
    curl 'https:///server/' -H 'accessId:' -H 'accessSecret:' -H 'Content-Type:text/plain' -d ''
    # POST request example
    curl 'https://dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com/server/database' -H 'accessId:user' -H 'accessSecret:pwd' -H 'Content-Type:text/plain' -d 'SHOW DATABASES'
  • Use a Python program

    Note

    This example uses Python 2.

    GET request:

    import requests
    url = "https:///server/?accessId=&accessSecret=&sql="
    print requests.get(url).text

    GET request example:

    import requests
    url = "https://dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com/server/database?accessId=user&accessSecret=pwd&sql=SHOW DATABASES"
    print requests.get(url).text

    POST request:

    import requests
    url = "https:///server/"
    headers = {
        "Content-Type": "text/plain;charset=utf-8",
        "accessId": "",
        "accessSecret": ""
    }
    print requests.post(url, headers=headers, data='').text

    POST request example:

    import requests
    url = "https://dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com/server/database"
    headers = {
        "Content-Type": "text/plain;charset=utf-8",
        "accessId": "user",
        "accessSecret": "pwd"
    }
    print requests.post(url, headers=headers, data='SHOW DATABASES').text
  • Use a Node.js program

    GET request:

    const https = require("https");
    https.get("https:///server/?accessId=&accessSecret=&sql=SHOW DATABASES", resp => {
        resp.on("data", data => {
            console.log(JSON.parse(data));
        });
    });

    GET request example:

    const https = require("https");
    https.get("https://dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com/server/database?accessId=user&accessSecret=pwd&sql=SHOW DATABASES", resp => {
        resp.on("data", data => {
            console.log(JSON.parse(data));
        });
    });

    POST request:

    const https = require("https");
    var req = https.request({
        hostname: '',
        port: 443,
        path: '/server/',
        method: 'POST',
        headers: {
            'Content-Type': 'text/plain; charset=UTF-8',
            accessId: '',
            accessSecret: ''
        }
    }, resp => {
        resp.on("data", data => {
            console.log(JSON.parse(data));
        });
    });
    req.write("");
    req.end();

    POST request example:

    const https = require("https");
    var req = https.request({
        hostname: 'dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com',
        port: 443,
        path: '/server/database',
        method: 'POST',
        headers: {
            'Content-Type': 'text/plain; charset=UTF-8',
            accessId: 'user',
            accessSecret: 'pwd'
        }
    }, resp => {
        resp.on("data", data => {
            console.log(JSON.parse(data));
        });
    });
    req.write("SHOW DATABASES");
    req.end();
  • Use the Postman client

    GET request: In Postman, send a GET request to the URL https://dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com/server/. In the URL parameters, set accessId to your AccessKey ID, accessSecret to your AccessKey Secret, and sql to the SQL statement that you want to execute, such as SHOW DATABASES. Click Send.

    POST request: In Postman, set the request method to POST and the URL to https://dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com/server/. On the Headers tab, add these headers: set Content-Type to text/plain, accessId to your AccessKey ID, and accessSecret to your AccessKey Secret. On the Body tab, select raw, choose Text, and enter the SQL statement, such as SHOW DATABASES, in the text area. Click Send.