Update an OSS data import jobs
Update the configuration of an existing OSS data import job by calling the UpdateOSSIngestion operation through the Simple Log Service SDK.
Prerequisites
-
Simple Log Service is activated.
-
Python is installed (see Install Python), a Python development environment is set up (see PyCharm), and a Python package management tool is installed (see pip).
-
The new version of Simple Log Service SDK for Python supports Python 3.7 and later.
-
Run the
python -Vcommand to check the installed Python version. -
Run the
pip3 -Vcommand to check the installed pip version.
-
-
The new version of Simple Log Service SDK for Python is installed.
-
Run the following command to install the new version of Simple Log Service SDK for Python:
pip install alibabacloud_sls20201230 -
After the installation is complete, run the following command to verify it:
pip show alibabacloud_sls20201230
-
-
The ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured. For more information, see Configure environment variables on Linux, macOS, and Windows.
Method signature
def update_ossingestion(
self,
project: str,
oss_ingestion_name: str,
request: sls_20201230_models.UpdateOSSIngestionRequest,
) -> sls_20201230_models.UpdateOSSIngestionResponse:
Request parameters
|
Name |
Type |
Required |
Description |
Example value |
|
project |
String |
Yes |
Name of the Simple Log Service project. |
ali-test-project |
|
oss_ingestion_name |
String |
Yes |
Name of the OSS data import job. |
ingest-oss-123456 |
|
request |
object |
Yes |
Configuration for updating the OSS data import job. |
- |
UpdateOSSIngestionRequest parameters
class UpdateOSSIngestionRequest(TeaModel):
def __init__(
self,
configuration: OSSIngestionConfiguration = None,
description: str = None,
display_name: str = None,
schedule: Schedule = None,
):
|
Name |
Type |
Required |
Description |
Example value |
|
configuration |
object |
Yes |
OSS data import configuration. |
- |
|
description |
String |
No |
Description of the job. |
This is an update description. |
|
display_name |
String |
Yes |
Display name of the job. |
OSS import test. |
|
schedule |
object |
No |
Scheduling type. Leave empty by default. |
- |
Schedule parameters
class Schedule(TeaModel):
def __init__(
self,
cron_expression: str = None,
delay: int = None,
interval: str = None,
run_immediately: bool = None,
time_zone: str = None,
type: str = None,
):
|
Parameter |
Type |
Required |
Description |
Example |
|
type |
String |
Yes |
The schedule type. Valid values: |
FixedRate |
|
cron_expression |
String |
No |
Required only when |
0/5 * * * * |
|
run_immediately |
bool |
No |
Whether to run the job immediately. |
True |
|
time_zone |
String |
No |
The time zone of the cron expression. Defaults to UTC+8 when empty. |
+0800 |
|
delay |
int |
No |
The delay before a scheduled job is run. Unit: seconds (s). |
4 |
|
interval |
String |
No |
The execution interval when |
1m |
OSSIngestionConfiguration parameters
class OSSIngestionConfiguration(TeaModel):
def __init__(
self,
logstore: str = None,
source: OSSIngestionConfigurationSource = None,
):
|
Name |
Type |
Required |
Description |
Example value |
|
logstore |
String |
Yes |
Name of the Logstore. |
test-logstore |
|
source |
object |
Yes |
OSS data import configuration. |
- |
OSSIngestionConfigurationSource parameters
class OSSIngestionConfigurationSource(TeaModel):
def __init__(
self,
bucket: str = None,
compression_codec: str = None,
encoding: str = None,
end_time: int = None,
endpoint: str = None,
format: Dict[str, Any] = None,
interval: str = None,
pattern: str = None,
prefix: str = None,
restore_object_enabled: bool = None,
role_arn: str = None,
start_time: int = None,
time_field: str = None,
time_format: str = None,
time_pattern: str = None,
time_zone: str = None,
use_meta_index: bool = None,
):
|
Name |
Type |
Required |
Description |
Example value |
|
bucket |
String |
Yes |
Name of the OSS bucket. |
ossbucket |
|
compression_code |
String |
Yes |
Compression type. |
none |
|
encoding |
String |
Yes |
Encoding type. |
UTF-8 |
|
endpoint |
String |
Yes |
OSS endpoint. |
oss-cn-hangzhou-internal.aliyuncs.com |
|
format |
Dictionary |
Data format of the OSS source.
|
{"type": "Line"} |
|
|
interval |
String |
Yes |
Interval for checking new files. |
60s |
|
pattern |
String |
No |
Regular expression for filtering file paths. |
.* |
|
prefix |
String |
No |
Prefix for filtering file paths. |
prefix |
|
restore_object_enabled |
bool |
No |
Whether to import archived objects. |
true |
|
role_arn |
String |
No |
ARN of the RAM role. |
acs:ram::12345:role/aliyunlogdefaultrole |
|
start_time |
int |
No |
UNIX timestamp. Only files modified after this time are imported. |
1714274081 |
|
time_field |
String |
No |
Time field to extract from logs. |
__time__ |
|
time_format |
String |
No |
Format of the time field. |
yyyy-MM-dd HH:mm:ss |
|
time_pattern |
String |
No |
Regular expression for extracting the time field. |
[0-9]{0,2}\/[0-9a-zA-Z]+\/[0-9:,]+ |
|
time_zone |
String |
No |
Time zone of the time field. |
GMT+08:00 |
|
use_meta_index |
bool |
Yes |
Whether to use the OSS metadata index. |
False |
Response parameters
For more information about response parameters, see UpdateOSSIngestion.
Sample code
import os
from alibabacloud_sls20201230.client import Client as Sls20201230Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_sls20201230 import models as sls_20201230_models
from alibabacloud_tea_util.client import Client as UtilClient
def main():
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
# Specify the Simple Log Service endpoint.
config.endpoint = "cn-hangzhou.log.aliyuncs.com"
project_name = "ali-test-project"
oss_ingestion_name = "ingest-oss-123456"
client = Sls20201230Client(config)
# Configure the OSS data source.
source = sls_20201230_models.OSSIngestionConfigurationSource(
bucket="ali-shanghai001",
compression_codec="none",
encoding="UTF-8",
end_time=None,
endpoint="oss-cn-hangzhou-internal.aliyuncs.com",
format={"type": "Line"},
interval="30s",
use_meta_index=False,
)
# Configure the OSS data import settings.
oss_config = sls_20201230_models.OSSIngestionConfiguration(
logstore="test-logtore",
source=source
)
# Build the update request.
update_ossingestions_request = sls_20201230_models.UpdateOSSIngestionRequest(
configuration=oss_config,
description="This is an update description",
display_name="OSS import test"
)
try:
update_ossingestions_response = client.update_ossingestion(project_name, oss_ingestion_name,
update_ossingestions_request)
print(update_ossingestions_response)
except Exception as error:
print(error.message)
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
main()
Related information
-
For more information about OSS data import API operations, see: