All Products
Search
Document Center

Simple Log Service:Update a scheduled SQL job

Last Updated:Dec 10, 2025

Call the UpdateScheduledSQL operation to update a scheduled SQL job.

Note

The Simple Log Service (SLS) SDK for Scheduled SQL is no longer updated. Use the Alibaba Cloud SDK to manage Scheduled SQL.

image

Prerequisites

Parameters

def update_scheduled_sql(self, project_name, scheduled_sql):

Request parameters

Parameter

Type

Required

Description

Example

project_name

String

Yes

The name of the project.

ali-test-project

scheduled_sql

object

Yes

The configurations of the scheduled SQL job.

-

scheduled_sql parameter

Parameter

Type

Required

Description

Example

name

String

Yes

The name of the scheduled SQL job. The name must meet the following requirements:

  • The name must be unique within a project.

  • The name can contain only lowercase letters, digits, hyphens (-), and underscores (_).

  • The name must start and end with a lowercase letter or a digit.

  • The name must be 4 to 63 characters in length.

test-001

displayName

String

Yes

The display name of the job.

test-001

description

String

No

The description of the job.

Create a scheduled SQL job.

schedule

object

Yes

The scheduling configuration of the job.

-

configuration

object

Yes

The configuration of the scheduled SQL job.

-

schedule parameter

Parameter

Type

Required

Description

Example

type

String

Yes

The type of the scheduled SQL job. The following five values are supported:

  • Cron: The job is scheduled based on the cron expression that you specify for the cronExpression parameter.

  • Hourly: The job is executed once every hour on the hour.

  • Daily: The job is executed once every day at the hour that you specify for the hour parameter.

  • Weekly: The job is executed once every week on the day and at the hour that you specify for the dayOfWeek and hour parameters.

  • FixedRate: The job is executed at a fixed interval. You can specify the interval for the interval parameter.

Cron

cronExpression

String

No

The cron expression.

0/5 * * * *

runImmediately

bool

No

Specifies whether to immediately run the scheduled job.

False

timeZone

String

No

The time zone of the cron expression. The default value is empty, which indicates the UTC+8 time zone.

+0800

delay

int

No

The delay before the job is executed. Unit: seconds. The value cannot be greater than 86400.

4

interval

String

No

If you set type to FixedRate, this parameter specifies the execution interval. The value cannot be greater than 30 days. The following units are supported: d (day), h (hour), m (minute), and s (second). Example: 3h. You cannot specify multiple units. For example, 3h5m is not supported.

1m

Configuration parameter

Parameter

Type

Required

Description

Example

script

String

Yes

The analytic statement of the scheduled SQL job.

* | select *

sqlType

String

Yes

The type of the SQL statement.

searchQuery

destEndpoint

String

Yes

The endpoint of the destination.

cn-hangzhou-intranet.log.aliyuncs.com

destProject

String

Yes

The destination project.

project-demo

sourceLogstore

String

Yes

The source Logstore.

source-logstore-demo

destLogstore

String

Yes

The destination Logstore.

dest-logstore-demo

roleArn

String

Yes

The Alibaba Cloud Resource Name (ARN) of the RAM role that is assumed to execute the SQL statement.

acs:ram::123456789:role/aliyunlogetlrole

destRoleArn

String

Yes

The ARN of the RAM role that is assumed to write data to the destination.

acs:ram::123456789:role/aliyunlogetlrole

fromTimeExpr

String

Yes

The beginning of the SQL time window.

@m-1m

toTimeExpr

String

Yes

The end of the SQL time window.

@m

maxRunTimeInSeconds

int

Yes

The maximum timeout period for the SQL statement. Unit: seconds. Valid values: 60 to 1800.

600

resourcePool

String

Yes

The type of the resource pool. The value enhanced indicates an enhanced resource pool.

enhanced

maxRetries

int

Yes

The maximum number of retries after an SQL statement times out. Valid values: 1 to 100.

20

fromTime

int

Yes

The start time. For more information, see Create a scheduled SQL job to import data from a Logstore to a Metricstore.

1712592000

toTime

int

Yes

The end time. For more information, see Create a scheduled SQL job to import data from a Logstore to a Metricstore.

0

dataFormat

String

Yes

The following three configurations are supported: log2log, log2metric, and metric2metric.

log2log

parameters

object

Yes

The SQL configuration. For more information, see Create a scheduled SQL job to import data from a Logstore to a Metricstore.

{
 addLabels: "{}",
 hashLabels: "[]",
 labelKeys: "[\"your label1\",\"your label2\"]",
 metricKeys: "[\"your Indicator1\",\"your Indicator2\"]",
 metricName: "",
 timeKey: ""
}

Response parameters

See UpdateScheduledSQL.

Sample code

import os
import time
from aliyun.log import LogClient
from aliyun.log.scheduled_sql import *

accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')  # The AccessKey ID.
accessKeySecret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')  # The AccessKey secret.

endpoint = "cn-hangzhou.log.aliyuncs.com"  # The endpoint of the project's region.
roleArn = "acs:ram::141******5616316:role/aliyunserviceroleforslsaudit"  # The role ARN.
project = "demo-test-project"  # The source project name.
source_logstore = "test-logstore"  # The source Logstore name.
source_metricstore = ""  # The source Metricstore name.

dest_endpoint = "cn-hangzhou.log.aliyuncs.com"  # The endpoint of the destination project's region.
dest_role_arn = "acs:ram::141******5616316:role/aliyunserviceroleforslsaudit"  # The destination role ARN.
dest_project = "demo-test-project"  # The destination project name.
dest_logstore = "test-logstore2"  # The destination Logstore name.
dest_metricstore = ""  # The destination Metricstore name.

from_time = int(time.time()) - 300  # The start time of the scheduled SQL job.

job_name = "test-001"  # The job name.
display_name = "test-001-update"  # The display name.
description = "Modify a scheduled SQL job"  # The description.

script = "* | select *"  # The SQL script.
promql = "* | select promql_query_range('key{}') from metrics limit 1000"  # The PromQL script.

instance_id = ""  # The instance ID of the scheduled SQL job.
delay_seconds = 0  # The delay for the scheduled SQL job in seconds.

# Three possible values for the data_format variable: "log2log", "log2metric", and "metric2metric".
data_format = "log2log"

# Possible values for the schedule_type variable: "FixedRate", "Daily", "Weekly", "Hourly", and "Cron".
# schedule_type = "FixedRate"
schedule_type = "FixedRate"

client = LogClient(endpoint, accessKeyId, accessKeySecret)


def update_schedule_sql():
    scheduled_sql_config = get_schedule_sql()

    configuration = scheduled_sql_config['configuration']
    schedule = scheduled_sql_config['schedule']

    configuration['fromTimeExpr'] = '@m-3m'
    configuration['maxRetries'] = 25

    schedule['type'] = 'Cron'
    schedule['timeZone'] = '+0800'
    schedule['interval'] = ''
    schedule['dayOfWeek'] = ''
    schedule['hour'] = ''
    schedule['cronExpression'] = '*/2 * * * *'

    schedule = dict_to_schedule_rule(schedule)
    configuration = dict_to_scheduled_sql_config(configuration)

    schedule_sql = ScheduledSQL()
    schedule_sql.setSchedule(schedule)
    schedule_sql.setConfiguration(configuration)
    schedule_sql.setName(job_name)
    schedule_sql.setDisplayName(display_name)
    schedule_sql.setDescription(description)

    update_schedule_sql_response = client.update_scheduled_sql(dest_project, schedule_sql)
    update_schedule_sql_response.log_print()


def get_schedule_sql():
    get_schedule_sql_response = client.get_scheduled_sql(dest_project, job_name)
    scheduled_sql_config = get_schedule_sql_response.scheduled_sql_config
    return scheduled_sql_config


if __name__ == "__main__":
    update_schedule_sql()
    pass

Sample response

UpdateScheduledSqlJobResponse:
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Fri, 01 Nov 2024 08:18:08 GMT', 'x-log-time': '1730449088', 'x-log-requestid': '67248EC069A98605C79EED79'}

Process finished with exit code 0

References