All Products
Search
Document Center

Simple Log Service:UpsertCollectionPolicy

Last Updated:Mar 27, 2026

Creates a log collection policy for a cloud service. This way, logs can be automatically collected from the service.

Operation description

You must use the Simple Log Service endpoint for the China (Shanghai) or Singapore region to call the operation.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request syntax

POST /collectionpolicy HTTP/1.1

Request parameters

Parameter

Type

Required

Description

Example

body

object

No

The body of the request.

policyName

string

Yes

The name must meet the following requirements:

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

  • The name must start with a letter.

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

your_log_policy

productCode

string

Yes

The code of the service.

oss

dataCode

string

Yes

The code of the log type.

access_log

enabled

boolean

Yes

Specifies whether to enable the policy.

true

policyConfig

object

Yes

The configurations of the policy.

resourceMode

string

Yes

The resource collection mode. Valid values: all, attributeMode, and instanceMode. The value all specifies that logs of all instances within your account are collected to the default logstore. The value attributeMode specifies that logs are collected based on the regions of instances and resource tags. The value instanceMode specifies that logs are collected based on instance IDs.

all

resourceTags

object

No

The resource tags. This parameter takes effect only when resourceMode is set to attributeMode. If you leave this parameter empty, resource tag-based filtering is not performed. The system considers that all instances are matched. If you specify a value for this parameter, logs of instances that use the specified resource tags are collected. Logs are collected from an instance only if the resource tags and region of the instance match the specified conditions.

{"tag1":"value1",“tag2":"value2"}

regions

array

No

The regions of the instances. This parameter takes effect only when resourceMode is set to attributeMode. Wildcard characters are supported. If you leave this parameter empty, region-based filtering is not performed. The system considers that all instances are matched. If you specify a value for this parameter, logs of instances that reside in the specified regions are collected. Logs are collected from an instance only if the resource tags and region of the instance match the specified conditions.

string

No

The ID of the region.

cn-hangzhou

instanceIds

array

No

The IDs of the instances. This parameter takes effect only when resourceMode is set to instanceMode. Logs are collected only from instances that use the specified IDs.

string

No

The ID of the instance.

your-test-bucket1

centralizeEnabled

boolean

No

Specifies whether to enable centralized storage. Default value: false.

false

centralizeConfig

object

No

The configurations of centralized storage.

destRegion

string

No

The destination region for centralized storage.

cn-beijing

destProject

string

No

The destination project for centralized storage. Make sure that the region of the destination project is consistent with the region specified by destRegion.

your-sls-project-in-beijing

destLogstore

string

No

The destination logstore for centralized storage. Make sure that the region of the destination logstore is consistent with the region specified by destRegion and the destination logstore belongs to the destination project specified by destProject.

your-sls-logstore-in-beijing

destTTL

integer

No

The data retention period for centralized storage. Unit: days. This parameter takes effect only when you use an existing logstore for centralized storage.

your-sls-logstore-ttl

dataConfig

object

No

The data configurations. The configuration is returned only for global logs. For example, if productCode is set to sls, the configuration is returned.

dataRegion

string

No

The region for storing the global logs that are collected for the first time.

cn-beijing

resourceDirectory

object

No

The configurations of the resource directory. The account must have activated the resource directory and be a management account or a delegated administrator of the resource directory.

accountGroupType

string

No

The mode of the resource directory. Valid values: all and custom.

all,custom

members

array

No

The members. If accountGroupType is set to custom, the members are returned.

string

No

The ID of the Alibaba Cloud account.

165***********50

Response elements

Element

Type

Description

Example

None defined.

For more information about error codes, see Manage collection rules in the new version of Log Audit Service.

Examples

Success response

JSON format

{}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.