All Products
Search
Document Center

ActionTrail:CreateTrail

Last Updated:Jul 24, 2025

ActionTrail records events for each Alibaba Cloud account for the last 90 days by default. To track events that occurred more than 90 days ago, you can create a trail to deliver operation events to Object Storage Service (OSS), Simple Log Service, or MaxCompute for event analysis.

Operation description

Note

Trails created through the API are in the shutdown state by default. You need to call the StartLogging operation to enable the trail before ActionTrail can deliver operation events to the target cloud product.

Prerequisites

Before you create a trail, ensure that you have completed at least one of the following storage configurations:

  • Deliver to Object Storage Service (OSS)

    Make sure you have activated Object Storage Service and created a bucket.

  • Deliver to Simple Log Service

    Make sure you have activated Simple Log Service and created a log project.

    Note

    When you create a trail, ActionTrail automatically creates a Logstore named actiontrail_<trail name> in the target log project. This Logstore prohibits other data from being written to ensure the accuracy of audit data.

  • Deliver to MaxCompute

    Make sure you have activated MaxCompute.

    Note

    When you create a trail, ActionTrail automatically creates a project named actiontrail_<account ID> in project management. This project prohibits other data from being written to ensure the accuracy of audit data.

Usage notes

This topic provides an example of creating a single-account trail named trail-test that delivers operation 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 support 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 to be created.
The name must be 6 to 36 characters in length and must start with a lowercase letter. It can contain lowercase letters, digits, hyphens (-), and underscores (_).

Note

Trail names must be unique within the same account.

trail-test

OssBucketName

string

No

The OSS bucket to which the trail delivers logs.
The name must be 3 to 63 characters in length and must start with a lowercase letter or digit. It can contain lowercase letters, digits, and hyphens (-).

Note

You must specify at least one of the following parameters: OssBucketName, SlsProjectArn, or MaxComputeProjectArn.

audit-log

OssKeyPrefix

string

No

The prefix of the file name in the OSS bucket to which the trail delivers logs. This parameter can be left empty.
The prefix must be 6 to 32 characters in length and must start with a letter. It can contain letters, digits, hyphens (-), forward slashes (/), and underscores (_).

at-product-account-audit-B

OssWriteRoleArn

string

No

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

  • If you do not specify this parameter, ActionTrail creates the required resources by creating a service-linked role. For more information, see ActionTrail service-linked role.

  • If you specify this parameter and want to deliver events to your current account, you need to grant the ActionTrail service-linked role permission to the RAM role. If you want to deliver events to another account, you need to attach the system policy for event delivery to the RAM role. 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 Simple Log Service project to which the trail delivers logs.

Note

You must specify at least one of the following parameters: OssBucketName, SlsProjectArn, or MaxComputeProjectArn.

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

SlsWriteRoleArn

string

No

The ARN of the role that ActionTrail assumes to deliver operation events to the Simple Log Service project.

  • If you do not specify this parameter, ActionTrail creates the required resources by creating a service-linked role. For more information, see ActionTrail service-linked role.

  • If you specify this parameter and want to deliver events to your current account, you need to grant the ActionTrail service-linked role permission to the RAM role. If you want to deliver events to another account, you need to attach the system policy for event delivery to the RAM role. 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

The read/write type of the events to be delivered. Valid values:

  • Write: write events.

  • Read: read events.

  • All (default): read and write events.

Write

TrailRegion

string

No

The region of the trail.
The default value is All, which indicates that the trail tracks events in all regions.
You can also specify a specific region. For more information about regions, call the DescribeRegions operation.




All

IsOrganizationTrail

boolean

No

Specifies whether to create a multi-account trail. Valid values:

  • true: creates a multi-account trail.

  • false (default): creates a single-account trail.

false

MaxComputeProjectArn

string

No

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

Note

You must specify at least one of the following parameters: OssBucketName, SlsProjectArn, or MaxComputeProjectArn.

Note

The name of the MaxCompute project specified in MaxComputeProjectArn must start with the actiontrail_ prefix.

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

MaxComputeWriteRoleArn

string

No

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

  • If you do not specify this parameter, ActionTrail creates the required resources by creating a service-linked role. For more information, see ActionTrail service-linked role.

  • If you specify this parameter and want to deliver events to your current account, you need to grant the ActionTrail service-linked role permission to the RAM role. If you want to deliver events to another account, you need to attach the system policy for event delivery to the RAM role. 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 parameters

Parameter

Type

Description

Example

object

EventRW

string

The read/write type of the events to be delivered.

Write

HomeRegion

string

The home region of the trail.

cn-hangzhou

MaxComputeProjectArn

string

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

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

MaxComputeWriteRoleArn

string

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

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

Name

string

The name of the trail.

trail-test

OssBucketName

string

The OSS bucket.

audit-log

OssKeyPrefix

string

The prefix of the file name in the OSS bucket.

at-product-account-audit-B

OssWriteRoleArn

string

The ARN of the role that ActionTrail assumes to deliver operation 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 Simple Log Service project to which the trail delivers logs.

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

SlsWriteRoleArn

string

The ARN of the role that ActionTrail assumes to deliver operation events to the Simple Log Service project.

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

TrailRegion

string

The region of the trail.

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.