2016/11/21 - AWS CloudTrail - 2 new2 updated api methods
Changes Update cloudtrail client to latest version
Configures an event selector for your trail. Use event selectors to specify the type of events that you want your trail to log. When an event occurs in your account, CloudTrail evaluates the event selectors in 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.
Example
You create an event selector for a trail and specify that you want write-only events.
The EC2 GetConsoleOutput and RunInstances API operations occur in your account.
CloudTrail evaluates whether the events match your event selectors.
The RunInstances is a write-only event and it matches your event selector. The trail logs the event.
The GetConsoleOutput is a read-only event but it doesn't match your event selector. The trail doesn't log the event.
The PutEventSelectors operation must be called from the region in which the trail was created; otherwise, an InvalidHomeRegionException is thrown.
You can configure up to five event selectors for each trail. For more information, see Configuring Event Selectors for Trails in the AWS CloudTrail User Guide.
Request Syntax
client.put_event_selectors( TrailName='string', EventSelectors=[ { 'ReadWriteType': 'ReadOnly'|'WriteOnly'|'All', 'IncludeManagementEvents': True|False, 'DataResources': [ { 'Type': 'string', 'Values': [ 'string', ] }, ] }, ] )
string
Specifies the name of the trail or trail ARN. If you specify a trail name, the string must meet the following requirements:
Contain only ASCII letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), or dashes (-)
Start with a letter or number, and end with a letter or number
Be between 3 and 128 characters
Have no adjacent periods, underscores or dashes. Names like my-_namespace and my--namespace are invalid.
Not be in IP address format (for example, 192.168.5.4)
If you specify a trail ARN, it must be in the format:
arn:aws:cloudtrail:us-east-1:123456789012:trail/MyTrail
list
Specifies the settings for your event selectors. You can configure up to five event selectors for a trail.
(dict) --
Use event selectors to specify the types of events that you want your trail to log. 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.
ReadWriteType (string) --
Specify if you want your trail to log read-only events, write-only events, or all. For example, the EC2 GetConsoleOutput is a read-only API operation and RunInstances is a write-only API operation.
By default, the value is All.
IncludeManagementEvents (boolean) --
Specify if you want your event selector to include management events for your trail.
For more information, see Management Events in the AWS CloudTrail User Guide.
By default, the value is true.
DataResources (list) --
CloudTrail supports logging only data events for S3 objects. You can specify up to 50 S3 buckets and object prefixes for an event selector.
For more information, see Data Events in the AWS CloudTrail User Guide.
(dict) --
The Amazon S3 objects that you specify in your event selectors for your trail to log data events. Data events are object level API operations that access S3 objects, such as GetObject, DeleteObject, and PutObject. You can specify up to 50 S3 buckets and object prefixes for an event selector.
Example
You create an event selector for a trail and specify an S3 bucket and an empty prefix, such as arn:aws:s3:::bucket-1/.
You upload an image file to bucket-1.
The PutObject API operation occurs on an object in the S3 bucket that you specified in the event selector. The trail processes and logs the event.
You upload another image file to a different S3 bucket named arn:aws:s3:::bucket-2.
The event occurs on an object in an S3 bucket that you didn't specify in the event selector. The trail doesn’t log the event.
Type (string) --
The resource type in which you want to log data events. You can specify only the following value: AWS::S3::Object.
Values (list) --
A list of ARN-like strings for the specified S3 objects.
To log data events for all objects in an S3 bucket, specify the bucket and an empty object prefix such as arn:aws:s3:::bucket-1/. The trail logs data events for all objects in this S3 bucket.
To log data events for specific objects, specify the S3 bucket and object prefix such as arn:aws:s3:::bucket-1/example-images. The trail logs data events for objects in this S3 bucket that match the prefix.
(string) --
dict
Response Syntax
{ 'TrailARN': 'string', 'EventSelectors': [ { 'ReadWriteType': 'ReadOnly'|'WriteOnly'|'All', 'IncludeManagementEvents': True|False, 'DataResources': [ { 'Type': 'string', 'Values': [ 'string', ] }, ] }, ] }
Response Structure
(dict) --
TrailARN (string) --
Specifies the ARN of the trail that was updated with event selectors. The format of a trail ARN is:
arn:aws:cloudtrail:us-east-1:123456789012:trail/MyTrail
EventSelectors (list) --
Specifies the event selectors configured for your trail.
(dict) --
Use event selectors to specify the types of events that you want your trail to log. 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.
ReadWriteType (string) --
Specify if you want your trail to log read-only events, write-only events, or all. For example, the EC2 GetConsoleOutput is a read-only API operation and RunInstances is a write-only API operation.
By default, the value is All.
IncludeManagementEvents (boolean) --
Specify if you want your event selector to include management events for your trail.
For more information, see Management Events in the AWS CloudTrail User Guide.
By default, the value is true.
DataResources (list) --
CloudTrail supports logging only data events for S3 objects. You can specify up to 50 S3 buckets and object prefixes for an event selector.
For more information, see Data Events in the AWS CloudTrail User Guide.
(dict) --
The Amazon S3 objects that you specify in your event selectors for your trail to log data events. Data events are object level API operations that access S3 objects, such as GetObject, DeleteObject, and PutObject. You can specify up to 50 S3 buckets and object prefixes for an event selector.
Example
You create an event selector for a trail and specify an S3 bucket and an empty prefix, such as arn:aws:s3:::bucket-1/.
You upload an image file to bucket-1.
The PutObject API operation occurs on an object in the S3 bucket that you specified in the event selector. The trail processes and logs the event.
You upload another image file to a different S3 bucket named arn:aws:s3:::bucket-2.
The event occurs on an object in an S3 bucket that you didn't specify in the event selector. The trail doesn’t log the event.
Type (string) --
The resource type in which you want to log data events. You can specify only the following value: AWS::S3::Object.
Values (list) --
A list of ARN-like strings for the specified S3 objects.
To log data events for all objects in an S3 bucket, specify the bucket and an empty object prefix such as arn:aws:s3:::bucket-1/. The trail logs data events for all objects in this S3 bucket.
To log data events for specific objects, specify the S3 bucket and object prefix such as arn:aws:s3:::bucket-1/example-images. The trail logs data events for objects in this S3 bucket that match the prefix.
(string) --
Describes the settings for the event selectors that you configured for your trail. The information returned for your event selectors includes the following:
The S3 objects that you are logging for data events.
If your event selector includes management events.
If your event selector includes read-only events, write-only events, or all.
For more information, see Configuring Event Selectors for Trails in the AWS CloudTrail User Guide.
Request Syntax
client.get_event_selectors( TrailName='string' )
string
Specifies the name of the trail or trail ARN. If you specify a trail name, the string must meet the following requirements:
Contain only ASCII letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), or dashes (-)
Start with a letter or number, and end with a letter or number
Be between 3 and 128 characters
Have no adjacent periods, underscores or dashes. Names like my-_namespace and my--namespace are invalid.
Not be in IP address format (for example, 192.168.5.4)
If you specify a trail ARN, it must be in the format:
arn:aws:cloudtrail:us-east-1:123456789012:trail/MyTrail
dict
Response Syntax
{ 'TrailARN': 'string', 'EventSelectors': [ { 'ReadWriteType': 'ReadOnly'|'WriteOnly'|'All', 'IncludeManagementEvents': True|False, 'DataResources': [ { 'Type': 'string', 'Values': [ 'string', ] }, ] }, ] }
Response Structure
(dict) --
TrailARN (string) --
The specified trail ARN that has the event selectors.
EventSelectors (list) --
The event selectors that are configured for the trail.
(dict) --
Use event selectors to specify the types of events that you want your trail to log. 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.
ReadWriteType (string) --
Specify if you want your trail to log read-only events, write-only events, or all. For example, the EC2 GetConsoleOutput is a read-only API operation and RunInstances is a write-only API operation.
By default, the value is All.
IncludeManagementEvents (boolean) --
Specify if you want your event selector to include management events for your trail.
For more information, see Management Events in the AWS CloudTrail User Guide.
By default, the value is true.
DataResources (list) --
CloudTrail supports logging only data events for S3 objects. You can specify up to 50 S3 buckets and object prefixes for an event selector.
For more information, see Data Events in the AWS CloudTrail User Guide.
(dict) --
The Amazon S3 objects that you specify in your event selectors for your trail to log data events. Data events are object level API operations that access S3 objects, such as GetObject, DeleteObject, and PutObject. You can specify up to 50 S3 buckets and object prefixes for an event selector.
Example
You create an event selector for a trail and specify an S3 bucket and an empty prefix, such as arn:aws:s3:::bucket-1/.
You upload an image file to bucket-1.
The PutObject API operation occurs on an object in the S3 bucket that you specified in the event selector. The trail processes and logs the event.
You upload another image file to a different S3 bucket named arn:aws:s3:::bucket-2.
The event occurs on an object in an S3 bucket that you didn't specify in the event selector. The trail doesn’t log the event.
Type (string) --
The resource type in which you want to log data events. You can specify only the following value: AWS::S3::Object.
Values (list) --
A list of ARN-like strings for the specified S3 objects.
To log data events for all objects in an S3 bucket, specify the bucket and an empty object prefix such as arn:aws:s3:::bucket-1/. The trail logs data events for all objects in this S3 bucket.
To log data events for specific objects, specify the S3 bucket and object prefix such as arn:aws:s3:::bucket-1/example-images. The trail logs data events for objects in this S3 bucket that match the prefix.
(string) --
{'trailList': {'HasCustomEventSelectors': 'boolean'}}
Retrieves settings for the trail associated with the current region for your account.
Request Syntax
client.describe_trails( trailNameList=[ 'string', ], includeShadowTrails=True|False )
list
Specifies a list of trail names, trail ARNs, or both, of the trails to describe. The format of a trail ARN is:
arn:aws:cloudtrail:us-east-1:123456789012:trail/MyTrail
If an empty list is specified, information for the trail in the current region is returned.
If an empty list is specified and IncludeShadowTrails is false, then information for all trails in the current region is returned.
If an empty list is specified and IncludeShadowTrails is null or true, then information for all trails in the current region and any associated shadow trails in other regions is returned.
(string) --
boolean
Specifies whether to include shadow trails in the response. A shadow trail is the replication in a region of a trail that was created in a different region. The default is true.
dict
Response Syntax
{ 'trailList': [ { 'Name': 'string', 'S3BucketName': 'string', 'S3KeyPrefix': 'string', 'SnsTopicName': 'string', 'SnsTopicARN': 'string', 'IncludeGlobalServiceEvents': True|False, 'IsMultiRegionTrail': True|False, 'HomeRegion': 'string', 'TrailARN': 'string', 'LogFileValidationEnabled': True|False, 'CloudWatchLogsLogGroupArn': 'string', 'CloudWatchLogsRoleArn': 'string', 'KmsKeyId': 'string', 'HasCustomEventSelectors': True|False }, ] }
Response Structure
(dict) --
Returns the objects or data listed below if successful. Otherwise, returns an error.
trailList (list) --
The list of trail objects.
(dict) --
The settings for a trail.
Name (string) --
Name of the trail set by calling CreateTrail. The maximum length is 128 characters.
S3BucketName (string) --
Name of the Amazon S3 bucket into which CloudTrail delivers your trail files. See Amazon S3 Bucket Naming Requirements.
S3KeyPrefix (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.
SnsTopicName (string) --
This field is deprecated. Use SnsTopicARN.
SnsTopicARN (string) --
Specifies the ARN of the Amazon SNS topic that CloudTrail uses to send notifications when log files are delivered. The format of a topic ARN is:
arn:aws:sns:us-east-1:123456789012:MyTopic
IncludeGlobalServiceEvents (boolean) --
Set to True to include AWS API calls from AWS global services such as IAM. Otherwise, False.
IsMultiRegionTrail (boolean) --
Specifies whether the trail belongs only to one region or exists in all regions.
HomeRegion (string) --
The region in which the trail was created.
TrailARN (string) --
Specifies the ARN of the trail. The format of a trail ARN is:
arn:aws:cloudtrail:us-east-1:123456789012:trail/MyTrail
LogFileValidationEnabled (boolean) --
Specifies whether log file validation is enabled.
CloudWatchLogsLogGroupArn (string) --
Specifies an Amazon Resource Name (ARN), a unique identifier that represents the log group to which CloudTrail logs will be delivered.
CloudWatchLogsRoleArn (string) --
Specifies the role for the CloudWatch Logs endpoint to assume to write to a user's log group.
KmsKeyId (string) --
Specifies the KMS key ID that encrypts the logs delivered by CloudTrail. The value is a fully specified ARN to a KMS key in the format:
arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012
HasCustomEventSelectors (boolean) --
Specifies if the trail has custom event selectors.
{'LookupAttributes': {'AttributeKey': {'EventSource'}}}Response
{'Events': {'EventSource': 'string'}}
Looks up API activity events captured by CloudTrail that create, update, or delete resources in your account. Events for a region can be looked up for the times in which you had CloudTrail turned on in that region during the last seven days. Lookup supports the following attributes:
Event ID
Event name
Resource name
Resource type
User name
All attributes are optional. The default number of results returned is 10, with a maximum of 50 possible. The response includes a token that you can use to get the next page of results.
Request Syntax
client.lookup_events( LookupAttributes=[ { 'AttributeKey': 'EventId'|'EventName'|'Username'|'ResourceType'|'ResourceName'|'EventSource', 'AttributeValue': 'string' }, ], StartTime=datetime(2015, 1, 1), EndTime=datetime(2015, 1, 1), MaxResults=123, NextToken='string' )
list
Contains a list of lookup attributes. Currently the list can contain only one item.
(dict) --
Specifies an attribute and value that filter the events returned.
AttributeKey (string) -- [REQUIRED]
Specifies an attribute on which to filter the events returned.
AttributeValue (string) -- [REQUIRED]
Specifies a value for the specified AttributeKey.
datetime
Specifies that only events that occur after or at the specified time are returned. If the specified start time is after the specified end time, an error is returned.
datetime
Specifies that only events that occur before or at the specified time are returned. If the specified end time is before the specified start time, an error is returned.
integer
The number of events to return. Possible values are 1 through 50. The default is 10.
string
The token to use to get the next page of results after a previous API call. This token must be passed in with the same parameters that were specified in the the original call. For example, if the original call specified an AttributeKey of 'Username' with a value of 'root', the call with NextToken should include those same parameters.
dict
Response Syntax
{ 'Events': [ { 'EventId': 'string', 'EventName': 'string', 'EventTime': datetime(2015, 1, 1), 'EventSource': 'string', 'Username': 'string', 'Resources': [ { 'ResourceType': 'string', 'ResourceName': 'string' }, ], 'CloudTrailEvent': 'string' }, ], 'NextToken': 'string' }
Response Structure
(dict) --
Contains a response to a LookupEvents action.
Events (list) --
A list of events returned based on the lookup attributes specified and the CloudTrail event. The events list is sorted by time. The most recent event is listed first.
(dict) --
Contains information about an event that was returned by a lookup request. The result includes a representation of a CloudTrail event.
EventId (string) --
The CloudTrail ID of the event returned.
EventName (string) --
The name of the event returned.
EventTime (datetime) --
The date and time of the event returned.
EventSource (string) --
The AWS service that the request was made to.
Username (string) --
A user name or role name of the requester that called the API in the event returned.
Resources (list) --
A list of resources referenced by the event returned.
(dict) --
Specifies the type and name of a resource referenced by an event.
ResourceType (string) --
The type of a resource referenced by the event returned. When the resource type cannot be determined, null is returned. Some examples of resource types are: Instance for EC2, Trail for CloudTrail, DBInstance for RDS, and AccessKey for IAM. For a list of resource types supported for event lookup, see Resource Types Supported for Event Lookup.
ResourceName (string) --
The name of the resource referenced by the event returned. These are user-created names whose values will depend on the environment. For example, the resource name might be "auto-scaling-test-group" for an Auto Scaling Group or "i-1234567" for an EC2 Instance.
CloudTrailEvent (string) --
A JSON string that contains a representation of the event returned.
NextToken (string) --
The token to use to get the next page of results after a previous API call. If the token does not appear, there are no more results to return. The token must be passed in with the same parameters as the previous call. For example, if the original call specified an AttributeKey of 'Username' with a value of 'root', the call with NextToken should include those same parameters.