Skip to main content

trails

Creates, updates, deletes or gets a trail resource or lists trails in a region

Overview

Nametrails
TypeResource
DescriptionCreates a trail that specifies the settings for delivery of log data to an Amazon S3 bucket. A maximum of five trails can exist in a region, irrespective of the region in which they were created.
Idaws.cloudtrail.trails

Fields

NameDatatypeDescription
cloud_watch_logs_log_group_arnstringSpecifies a log group name using an Amazon Resource Name (ARN), a unique identifier that represents the log group to which CloudTrail logs will be delivered. Not required unless you specify CloudWatchLogsRoleArn.
cloud_watch_logs_role_arnstringSpecifies the role for the CloudWatch Logs endpoint to assume to write to a user's log group.
enable_log_file_validationbooleanSpecifies whether log file validation is enabled. The default is false.
advanced_event_selectorsarrayThe advanced event selectors that were used to select events for the data store.
event_selectorsarrayUse event selectors to further specify the management and data event settings for your trail. By default, trails created without specific event selectors will be configured to log all read and write management events, and no data events. When an event occurs in your account, CloudTrail evaluates the event selector for all trails. For each trail, if the event matches any event selector, the trail processes and logs the event. If the event doesn't match any event selector, the trail doesn't log the event. You can configure up to five event selectors for a trail.
include_global_service_eventsbooleanSpecifies whether the trail is publishing events from global services such as IAM to the log files.
is_loggingbooleanWhether the CloudTrail is currently logging AWS API calls.
is_multi_region_trailbooleanSpecifies whether the trail applies only to the current region or to all regions. The default is false. If the trail exists only in the current region and this value is set to true, shadow trails (replications of the trail) will be created in the other regions. If the trail exists in all regions and this value is set to false, the trail will remain in the region where it was created, and its shadow trails in other regions will be deleted. As a best practice, consider using trails that log events in all regions.
is_organization_trailbooleanSpecifies whether the trail is created for all accounts in an organization in AWS Organizations, or only for the current AWS account. The default is false, and cannot be true unless the call is made on behalf of an AWS account that is the master account for an organization in AWS Organizations.
kms_key_idstringSpecifies the KMS key ID to use to encrypt the logs delivered by CloudTrail. The value can be an alias name prefixed by 'alias/', a fully specified ARN to an alias, a fully specified ARN to a key, or a globally unique identifier.
s3_bucket_namestringSpecifies the name of the Amazon S3 bucket designated for publishing log files. See Amazon S3 Bucket Naming Requirements.
s3_key_prefixstringSpecifies the Amazon S3 key prefix that comes after the name of the bucket you have designated for log file delivery. For more information, see Finding Your CloudTrail Log Files. The maximum length is 200 characters.
sns_topic_namestringSpecifies the name of the Amazon SNS topic defined for notification of log file delivery. The maximum length is 256 characters.
tagsarray
trail_namestring
arnstring
sns_topic_arnstring
insight_selectorsarrayLets you enable Insights event logging by specifying the Insights selectors that you want to enable on an existing trail.
regionstringAWS region.

Methods

NameAccessible byRequired Params
create_resourceINSERTS3BucketName, IsLogging, region
delete_resourceDELETEdata__Identifier, region
update_resourceUPDATEdata__Identifier, data__PatchDocument, region
list_resourcesSELECTregion
get_resourceSELECTdata__Identifier, region

SELECT examples

Gets all trails in a region.

SELECT
region,
cloud_watch_logs_log_group_arn,
cloud_watch_logs_role_arn,
enable_log_file_validation,
advanced_event_selectors,
event_selectors,
include_global_service_events,
is_logging,
is_multi_region_trail,
is_organization_trail,
kms_key_id,
s3_bucket_name,
s3_key_prefix,
sns_topic_name,
tags,
trail_name,
arn,
sns_topic_arn,
insight_selectors
FROM aws.cloudtrail.trails
WHERE region = 'us-east-1';

Gets all properties from an individual trail.

SELECT
region,
cloud_watch_logs_log_group_arn,
cloud_watch_logs_role_arn,
enable_log_file_validation,
advanced_event_selectors,
event_selectors,
include_global_service_events,
is_logging,
is_multi_region_trail,
is_organization_trail,
kms_key_id,
s3_bucket_name,
s3_key_prefix,
sns_topic_name,
tags,
trail_name,
arn,
sns_topic_arn,
insight_selectors
FROM aws.cloudtrail.trails
WHERE region = 'us-east-1' AND data__Identifier = '<TrailName>';

INSERT example

Use the following StackQL query and manifest file to create a new trail resource, using stack-deploy.

/*+ create */
INSERT INTO aws.cloudtrail.trails (
IsLogging,
S3BucketName,
region
)
SELECT
'{{ IsLogging }}',
'{{ S3BucketName }}',
'{{ region }}';

DELETE example

/*+ delete */
DELETE FROM aws.cloudtrail.trails
WHERE data__Identifier = '<TrailName>'
AND region = 'us-east-1';

Permissions

To operate on the trails resource, the following permissions are required:

Create

CloudTrail:CreateTrail,
CloudTrail:StartLogging,
CloudTrail:AddTags,
CloudTrail:PutEventSelectors,
CloudTrail:PutInsightSelectors,
iam:GetRole,
iam:PassRole,
iam:CreateServiceLinkedRole,
organizations:DescribeOrganization,
organizations:ListAWSServiceAccessForOrganization

Read

CloudTrail:GetTrail,
CloudTrail:GetTrailStatus,
CloudTrail:ListTags,
CloudTrail:GetEventSelectors,
CloudTrail:GetInsightSelectors,
CloudTrail:DescribeTrails

Update

CloudTrail:UpdateTrail,
CloudTrail:StartLogging,
CloudTrail:StopLogging,
CloudTrail:AddTags,
CloudTrail:RemoveTags,
CloudTrail:PutEventSelectors,
CloudTrail:PutInsightSelectors,
iam:GetRole,
iam:PassRole,
iam:CreateServiceLinkedRole,
organizations:DescribeOrganization,
organizations:ListAWSServiceAccessForOrganization,
CloudTrail:GetTrail,
CloudTrail:DescribeTrails

Delete

CloudTrail:DeleteTrail

List

CloudTrail:ListTrails,
CloudTrail:GetTrail,
CloudTrail:GetTrailStatus,
CloudTrail:ListTags,
CloudTrail:GetEventSelectors,
CloudTrail:GetInsightSelectors,
CloudTrail:DescribeTrails