trails
Creates, updates, deletes or gets a trail resource or lists trails in a region
Overview
| Name | trails |
| Type | Resource |
| Description | Creates 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. |
| Id | awscc.cloudtrail.trails |
Fields
- get (all properties)
- list (identifiers only)
| Name | Datatype | Description |
|---|---|---|
include_global_service_events | boolean | Specifies whether the trail is publishing events from global services such as IAM to the log files. |
event_selectors | array | Use 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. |
kms_key_id | string | Specifies 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. |
cloud_watch_logs_role_arn | string | Specifies the role for the CloudWatch Logs endpoint to assume to write to a user's log group. |
s3_key_prefix | string | Specifies 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. |
advanced_event_selectors | array | The advanced event selectors that were used to select events for the data store. |
trail_name | string | |
is_organization_trail | boolean | Specifies 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. |
insight_selectors | array | Lets you enable Insights event logging by specifying the Insights selectors that you want to enable on an existing trail. |
cloud_watch_logs_log_group_arn | string | Specifies 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. |
sns_topic_name | string | Specifies the name of the Amazon SNS topic defined for notification of log file delivery. The maximum length is 256 characters. |
is_multi_region_trail | boolean | Specifies 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. |
s3_bucket_name | string | Specifies the name of the Amazon S3 bucket designated for publishing log files. See Amazon S3 Bucket Naming Requirements. |
sns_topic_arn | string | |
enable_log_file_validation | boolean | Specifies whether log file validation is enabled. The default is false. |
arn | string | |
tags | array | |
is_logging | boolean | Whether the CloudTrail is currently logging AWS API calls. |
region | string | AWS region. |
| Name | Datatype | Description |
|---|---|---|
trail_name | string | |
region | string | AWS region. |
For more information, see AWS::CloudTrail::Trail.
Methods
| Name | Resource | Accessible by | Required Params |
|---|---|---|---|
create_resource | trails | INSERT | S3BucketName, IsLogging, region |
delete_resource | trails | DELETE | Identifier, region |
update_resource | trails | UPDATE | Identifier, PatchDocument, region |
list_resources | trails_list_only | SELECT | region |
get_resource | trails | SELECT | Identifier, region |
SELECT examples
- get (all properties)
- list (identifiers only)
Gets all properties from an individual trail.
SELECT
region,
include_global_service_events,
event_selectors,
kms_key_id,
cloud_watch_logs_role_arn,
s3_key_prefix,
advanced_event_selectors,
trail_name,
is_organization_trail,
insight_selectors,
cloud_watch_logs_log_group_arn,
sns_topic_name,
is_multi_region_trail,
s3_bucket_name,
sns_topic_arn,
enable_log_file_validation,
arn,
tags,
is_logging
FROM awscc.cloudtrail.trails
WHERE
region = 'us-east-1' AND
Identifier = '{{ trail_name }}';
Lists all trails in a region.
SELECT
region,
trail_name
FROM awscc.cloudtrail.trails_list_only
WHERE
region = 'us-east-1';
INSERT example
Use the following StackQL query and manifest file to create a new trail resource, using stack-deploy.
- Required Properties
- All Properties
- Manifest
/*+ create */
INSERT INTO awscc.cloudtrail.trails (
S3BucketName,
IsLogging,
region
)
SELECT
'{{ s3_bucket_name }}',
'{{ is_logging }}',
'{{ region }}';
/*+ create */
INSERT INTO awscc.cloudtrail.trails (
IncludeGlobalServiceEvents,
EventSelectors,
KMSKeyId,
CloudWatchLogsRoleArn,
S3KeyPrefix,
AdvancedEventSelectors,
TrailName,
IsOrganizationTrail,
InsightSelectors,
CloudWatchLogsLogGroupArn,
SnsTopicName,
IsMultiRegionTrail,
S3BucketName,
EnableLogFileValidation,
Tags,
IsLogging,
region
)
SELECT
'{{ include_global_service_events }}',
'{{ event_selectors }}',
'{{ kms_key_id }}',
'{{ cloud_watch_logs_role_arn }}',
'{{ s3_key_prefix }}',
'{{ advanced_event_selectors }}',
'{{ trail_name }}',
'{{ is_organization_trail }}',
'{{ insight_selectors }}',
'{{ cloud_watch_logs_log_group_arn }}',
'{{ sns_topic_name }}',
'{{ is_multi_region_trail }}',
'{{ s3_bucket_name }}',
'{{ enable_log_file_validation }}',
'{{ tags }}',
'{{ is_logging }}',
'{{ region }}';
version: 1
name: stack name
description: stack description
providers:
- aws
globals:
- name: region
value: '{{ vars.AWS_REGION }}'
resources:
- name: trail
props:
- name: include_global_service_events
value: '{{ include_global_service_events }}'
- name: event_selectors
value:
- include_management_events: '{{ include_management_events }}'
read_write_type: '{{ read_write_type }}'
exclude_management_event_sources:
- '{{ exclude_management_event_sources[0] }}'
data_resources:
- type: '{{ type }}'
values:
- '{{ values[0] }}'
- name: kms_key_id
value: '{{ kms_key_id }}'
- name: cloud_watch_logs_role_arn
value: '{{ cloud_watch_logs_role_arn }}'
- name: s3_key_prefix
value: '{{ s3_key_prefix }}'
- name: advanced_event_selectors
value:
- field_selectors:
- field: '{{ field }}'
equals:
- '{{ equals[0] }}'
not_starts_with:
- '{{ not_starts_with[0] }}'
not_ends_with:
- '{{ not_ends_with[0] }}'
starts_with:
- '{{ starts_with[0] }}'
ends_with:
- '{{ ends_with[0] }}'
not_equals:
- '{{ not_equals[0] }}'
name: '{{ name }}'
- name: trail_name
value: '{{ trail_name }}'
- name: is_organization_trail
value: '{{ is_organization_trail }}'
- name: insight_selectors
value:
- insight_type: '{{ insight_type }}'
- name: cloud_watch_logs_log_group_arn
value: '{{ cloud_watch_logs_log_group_arn }}'
- name: sns_topic_name
value: '{{ sns_topic_name }}'
- name: is_multi_region_trail
value: '{{ is_multi_region_trail }}'
- name: s3_bucket_name
value: '{{ s3_bucket_name }}'
- name: enable_log_file_validation
value: '{{ enable_log_file_validation }}'
- name: tags
value:
- value: '{{ value }}'
key: '{{ key }}'
- name: is_logging
value: '{{ is_logging }}'
UPDATE example
Use the following StackQL query and manifest file to update a trail resource, using stack-deploy.
/*+ update */
UPDATE awscc.cloudtrail.trails
SET PatchDocument = string('{{ {
"IncludeGlobalServiceEvents": include_global_service_events,
"EventSelectors": event_selectors,
"KMSKeyId": kms_key_id,
"CloudWatchLogsRoleArn": cloud_watch_logs_role_arn,
"S3KeyPrefix": s3_key_prefix,
"AdvancedEventSelectors": advanced_event_selectors,
"IsOrganizationTrail": is_organization_trail,
"InsightSelectors": insight_selectors,
"CloudWatchLogsLogGroupArn": cloud_watch_logs_log_group_arn,
"SnsTopicName": sns_topic_name,
"IsMultiRegionTrail": is_multi_region_trail,
"S3BucketName": s3_bucket_name,
"EnableLogFileValidation": enable_log_file_validation,
"Tags": tags,
"IsLogging": is_logging
} | generate_patch_document }}')
WHERE
region = '{{ region }}' AND
Identifier = '{{ trail_name }}';
DELETE example
/*+ delete */
DELETE FROM awscc.cloudtrail.trails
WHERE
Identifier = '{{ trail_name }}' AND
region = 'us-east-1';
Permissions
To operate on the trails resource, the following permissions are required:
- Read
- Create
- Update
- List
- Delete
CloudTrail:GetTrail,
CloudTrail:GetTrailStatus,
CloudTrail:ListTags,
CloudTrail:GetEventSelectors,
CloudTrail:GetInsightSelectors,
CloudTrail:DescribeTrails
CloudTrail:CreateTrail,
CloudTrail:StartLogging,
CloudTrail:AddTags,
CloudTrail:PutEventSelectors,
CloudTrail:PutInsightSelectors,
iam:GetRole,
iam:PassRole,
iam:CreateServiceLinkedRole,
organizations:DescribeOrganization,
organizations:ListAWSServiceAccessForOrganization
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
CloudTrail:ListTrails,
CloudTrail:GetTrail,
CloudTrail:GetTrailStatus,
CloudTrail:ListTags,
CloudTrail:GetEventSelectors,
CloudTrail:GetInsightSelectors,
CloudTrail:DescribeTrails
CloudTrail:DeleteTrail