All Products
Search
Document Center

ActionTrail:CreateTrail

更新時間:Jan 14, 2026

Creates a trail to deliver events to a destination for long-term storage and analysis, such as an Object Storage Service (OSS) bucket, a Simple Log Service (SLS) Logstore, or a MaxCompute project.

Operation description

Note

By default, a trail that you create by using this API is in a disabled state. You must call the StartLogging operation operation to enable the trail. After a trail is enabled, ActionTrail begins delivering events to your specified destination.

Prerequisites

Before you create a trail, you must have at least one of the following resources configured as a destination:

  • OSS

    You must activate OSS and create a bucket.

  • SLS

    You must activate SLS and create a Logstore.

    Note

    When you create a trail with an SLS destination, ActionTrail automatically creates a Logstore named actiontrail_<trail_name> in your specified project. To ensure the integrity of your audit data, this Logstore only accepts events delivered by ActionTrail.

  • MaxCompute

    You must activate MaxCompute.

    Note

    When you create a trail with a MaxCompute destination, ActionTrail automatically creates a project named actiontrail_<account_ID>. To ensure the integrity of your audit data, this project only accepts events delivered by ActionTrail.

Usage notes

This example shows how to create a single-account trail named trail-test that delivers events to an OSS bucket named audit-log.

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

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

actiontrail:CreateTrail

create

*Trail

acs:actiontrail:{#regionId}:{#accountId}:trail/*

None

None

Request parameters

Parameter

Type

Required

Description

Example

Name

string

Yes

The name of the trail.

Note
  • Length: 6 to 36 characters.

  • Characters: Lowercase letters, digits, hyphens (-), and underscores (_).

  • Must start with a lowercase letter.

  • Must be uniquewithin an Alibaba Cloud account.

trail-test

OssBucketName

string

No

The name of the OSS bucket to which ActionTrail delivers events.

  • Length: 3 to 63 characters.

  • Characters: Lowercase letters, digits, and hyphens (-).

  • Must start with a lowercase letter or a digit.

Note

You must specify a destination for the trail by providing at least one of the following parameters: OssBucketName, SlsProjectArn, or MaxComputeProjectArn.

audit-log

OssKeyPrefix

string

No

The prefix for the names of log files that ActionTrail delivers to your OSS bucket.

  • Length: 6 to 32 characters.

  • Characters: Letters, digits, hyphens (-), forward slashes (/), and underscores (_).

  • Must start with a letter.

at-product-account-audit-B

OssWriteRoleArn

string

No

The Alibaba Cloud Resource Name (ARN) of the RAM role that ActionTrail assumes to deliver events to the OSS bucket.

  • If you do not specify this parameter, ActionTrail creates a service-linked role to deliver events. For more information, see ActionTrail service-linked role.

  • If you specify a role, it must be a RAM role that you created. This role must have a trust policy that allows the ActionTrail service (actiontrail.aliyuncs.com) to assume it. The role's RAM policy must grant permissions to write to the specified OSS bucket. For more information about cross-account delivery, see Deliver events from multiple Alibaba Cloud accounts to the same account.

acs:ram::***:role/aliyunserviceroleforactiontrail

SlsProjectArn

string

No

The ARN of the SLS project to which ActionTrail delivers events.

Note

You must specify a destination for the trail by providing at least one of the following parameters: OssBucketName, SlsProjectArn, or MaxComputeProjectArn.

acs:log:cn-shanghai::project/***

SlsWriteRoleArn

string

No

The ARN of the RAM role that ActionTrail assumes to deliver events to the SLS project.

  • If this parameter is not specified, ActionTrail creates a service-linked role to deliver events. For more information, see ActionTrail service-linked role.

  • If you specify a role, it must be a RAM role that you created. This role must have a trust policy that allows the ActionTrail service (actiontrail.aliyuncs.com) to assume it. The role's permission policy must grant permissions to write to the specified SLS project. For more information about cross-account delivery, see Deliver events from multiple Alibaba Cloud accounts to the same account.

acs:ram::***:role/aliyunserviceroleforactiontrail

EventRW

string

No

Specifies the read/write type of events that the trail delivers. Valid values:

  • Write: Write events.

  • Read: Read events.

  • All (default): All read and write events.

Write

TrailRegion

string

No

The region in which the trail is created. By default, a trail is created in all regions and this parameter is set to All. To create a trail in a specific region, provide the region ID. For more information about regions, call the DescribeRegions operation.

All

IsOrganizationTrail

boolean

No

Specifies whether the trail is a multi-account trail. Valid values:

  • true

  • false (default)

To create a trail for an organization, set this parameter to true. The trail will collect events from all member accounts in the organization.

false

MaxComputeProjectArn

string

No

The ARN of the MaxCompute project to which ActionTrail delivers events.

Note

You must specify a destination for the trail by providing at least one of the following parameters: OssBucketName, SlsProjectArn, or MaxComputeProjectArn.

Note

The project name in the ARN must start with actiontrail_.

acs:odps:cn-hangzhou:15127787691****:project/actiontrail_****

MaxComputeWriteRoleArn

string

No

The ARN of the RAM role that ActionTrail assumes to deliver events to the MaxCompute project.

  • If this parameter is not specified, ActionTrail creates a service-linked role to deliver events. For more information, see ActionTrail service-linked role.

  • If you specify a role, it must be a RAM role that you created. This role must have a trust policy that allows the ActionTrail service (`actiontrail.aliyuncs.com`) to assume it. The role's permission policy must grant permissions to write to the specified MaxCompute project. For more information about cross-account delivery, see Deliver events from multiple Alibaba Cloud accounts to the same account.

acs:ram::15127787691****:role/aliyunserviceroleforactiontrail

For more information, see Common parameters.

Response elements

Parameter

Type

Description

Example

object

EventRW

string

The read/write type of events that the trail delivers.

Write

HomeRegion

string

The home region of the trail.

cn-hangzhou

MaxComputeProjectArn

string

The ARN of the MaxCompute project to which the trail delivers events.

acs:odps:cn-hangzhou:151266687691****:project/actiontrail_****

MaxComputeWriteRoleArn

string

The ARN of the RAM role that ActionTrail assumes to deliver events to the MaxCompute project.

acs:ram::151266687691****:role/aliyunserviceroleforactiontrail

Name

string

The name of the trail.

trail-test

OssBucketName

string

The name of the destination OSS bucket.

audit-log

OssKeyPrefix

string

The prefix for the names of log files in the OSS bucket.

at-product-account-audit-B

OssWriteRoleArn

string

The ARN of the RAM role that ActionTrail assumes to deliver events to the OSS bucket.

acs:ram::***:role/aliyunserviceroleforactiontrail

RequestId

string

The request ID.

442DDADF-DA58-4029-8E8B-82C73E9A7A70

SlsProjectArn

string

The ARN of the SLS project to which the trail delivers events.

acs:log:cn-hangzhou:151266687691****:project/test-project

SlsWriteRoleArn

string

The ARN of the RAM role that ActionTrail assumes to deliver events to the SLS project.

acs:ram::***:role/aliyunserviceroleforactiontrail

TrailRegion

string

The region in which the trail is created. A value of All indicates that the trail processes events from all regions.

All

Examples

Success response

JSON format

{
  "EventRW": "Write",
  "HomeRegion": "cn-hangzhou",
  "MaxComputeProjectArn": "acs:odps:cn-hangzhou:151266687691****:project/actiontrail_****",
  "MaxComputeWriteRoleArn": "acs:ram::151266687691****:role/aliyunserviceroleforactiontrail",
  "Name": "trail-test",
  "OssBucketName": "audit-log",
  "OssKeyPrefix": "at-product-account-audit-B",
  "OssWriteRoleArn": "acs:ram::***:role/aliyunserviceroleforactiontrail",
  "RequestId": "442DDADF-DA58-4029-8E8B-82C73E9A7A70",
  "SlsProjectArn": "acs:log:cn-hangzhou:151266687691****:project/test-project",
  "SlsWriteRoleArn": "acs:ram::***:role/aliyunserviceroleforactiontrail",
  "TrailRegion": "All"
}

Error codes

HTTP status code

Error code

Error message

Description

400

InvalidDeliveryConfigurationException

You must specify at least one Log Service project or OSS bucket for a Trail.

400

InvalidPrefixException

The specified OSS bucket prefix is invalid.

The specified OSS bucket prefix is not valid.

400

InvalidQueryParameter

The specified query parameter is invalid.

The specified query parameter is not valid.

400

InvalidTrailNameException

The specified Trail name is invalid.

The specified Trail name is not valid.

400

RepeatOssBucket

The specified OSS bucket is already in use. We recommend that you modify the existing Trail or specify another bucket.

400

SlsProjectDoesNotExistException

The specified Log Service project does not exist.

400

TrailAlreadyExistsException

The specified Trail name already exists.

The specified Trail name already exists,if you want to create a new Trail,please use another Trail name.

400

MaximumNumberOfOrganizationTrailExceeded

Your account can create only one organization trail.

400

NotAllowCreateOrganizationTrail

Your account does not allow you to create organization trail. Submit a ticket to get customer support.

403

InsufficientBucketPolicyException

Access to the specified OSS bucket was denied.

403

InsufficientSlsPolicyException

Access to the specified Log Service project was denied.

Access SLS Project denied.

403

MaximumNumberOfTrailsExceededException

The number of Trails in the same region exceeds the upper limit (5).

The number of Trail in same region has exceeded the limit 5

404

BucketDoesNotExistException

The specified OSS bucket does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.