All Products
Search
Document Center

Simple Log Service:Enable the Dedicated SQL feature

Last Updated:Feb 13, 2025

Call the CreateSqlInstance API to enable the Dedicated SQL feature.

Prerequisites

Parameter description

def create_sql_instance(self, project_name, sql_instance,useAsDefault):

Request parameters

Parameter

Type

Required

Description

Example

project_name

String

Yes

The name of the project for which you want to enable the Dedicated SQL feature.

demo-test-project

sql_instance

int

Yes

The number of compute units (CUs). When you use the Dedicated SQL feature, CUs are used in parallel.

500

useAsDefault

bool

Yes

Specifies whether to enable the Dedicated SQL feature by default for the project. If you set this parameter to true, the Dedicated SQL feature is enabled for the specified project and takes effect for all query statements that you execute in the project. This includes the query statements for alerts and dashboards.

False

Response parameters

For more information, see CreateSqlInstance.

Sample code

from aliyun.log import LogClient
import os


def main():
    # The Simple Log Service endpoint. For more information, see Endpoints. In this example, the Simple Log Service endpoint for the China (Hangzhou) region is used. Replace this parameter value with your actual endpoint.
    endpoint = 'cn-hangzhou.log.aliyuncs.com'
    # In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
    access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    access_key = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
    # The name of the project.
    project_name = 'demo-test-project'

    # Create a Simple Log Service client.
    client = LogClient(endpoint, access_key_id, access_key)

    # Create an SQL instance. You can specify the number of CUs for the SQL instance. Valid values: 0 to 1000.
    print("===sample_create_sql_instance===")
    res = client.create_sql_instance(project_name, 500, False)
    res.log_print()

    # Obtain the configurations of the SQL instance.
    print("===sample_list_sql_instance===")
    res = client.list_sql_instance(project_name)
    res.log_print()


if __name__ == '__main__':
    main()

Sample response

===sample_create_sql_instance===
CreateSqlInstanceResponse:
request_id: 6729B91518FF9F4603162886
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 05 Nov 2024 06:20:06 GMT', 'x-log-time': '1730787606', 'x-log-requestid': '6729B91518FF9F4603162886'}
response: 
===sample_list_sql_instance===
ListSqlInstanceResponse:
request_id: 6729B916D86F8B7ED6F5A15F
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '152', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 05 Nov 2024 06:20:06 GMT', 'x-log-time': '1730787606', 'x-log-requestid': '6729B916D86F8B7ED6F5A15F'}
response: [{'createTime': 1730786020, 'cu': 500, 'name': 'group1', 'updateTime': 1730787605, 'useAsDefault': False}]

Process finished with exit code 0