Table of Contents
CloudTrail.Client¶A low-level client representing AWS CloudTrail:
client = session.create_client('cloudtrail')
These are the available methods:
add_tags()can_paginate()create_trail()delete_trail()describe_trails()generate_presigned_url()get_event_selectors()get_paginator()get_trail_status()get_waiter()list_public_keys()list_tags()lookup_events()put_event_selectors()remove_tags()start_logging()stop_logging()update_trail()Adds one or more tags to a trail, up to a limit of 50. Tags must be unique per trail. Overwrites an existing tag’s value when a new value is specified for an existing tag key. If you specify a key without a value, the tag will be created with the specified key and a value of null. You can tag a trail that applies to all regions only from the region in which the trail was created (that is, from its home region).
See also: AWS API Documentation
Request Syntax
response = client.add_tags(
ResourceId='string',
TagsList=[
{
'Key': 'string',
'Value': 'string'
},
]
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {}
Response Structure
|
can_paginate(operation_name)¶Check if an operation can be paginated.
| Parameters: | operation_name (string) – The operation name. This is the same name
as the method name on the client. For example, if the
method name is create_foo, and you’d normally invoke the
operation as client.create_foo(**kwargs), if the
create_foo operation can be paginated, you can use the
call client.get_paginator("create_foo"). |
|---|---|
| Returns: | True if the operation can be paginated,
False otherwise. |
create_trail(**kwargs)¶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.
See also: AWS API Documentation
Request Syntax
response = client.create_trail(
Name='string',
S3BucketName='string',
S3KeyPrefix='string',
SnsTopicName='string',
IncludeGlobalServiceEvents=True|False,
IsMultiRegionTrail=True|False,
EnableLogFileValidation=True|False,
CloudWatchLogsLogGroupArn='string',
CloudWatchLogsRoleArn='string',
KmsKeyId='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'Name': 'string',
'S3BucketName': 'string',
'S3KeyPrefix': 'string',
'SnsTopicName': 'string',
'SnsTopicARN': 'string',
'IncludeGlobalServiceEvents': True|False,
'IsMultiRegionTrail': True|False,
'TrailARN': 'string',
'LogFileValidationEnabled': True|False,
'CloudWatchLogsLogGroupArn': 'string',
'CloudWatchLogsRoleArn': 'string',
'KmsKeyId': 'string'
}
Response Structure
|
delete_trail(**kwargs)¶Deletes a trail. This operation must be called from the region in which the trail was created. DeleteTrail cannot be called on the shadow trails (replicated trails in other regions) of a trail that is enabled in all regions.
See also: AWS API Documentation
Request Syntax
response = client.delete_trail(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] Specifies the name or the CloudTrail ARN of the trail to be deleted. The format of a trail ARN is: |
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{}
Response Structure
|
describe_trails(**kwargs)¶Retrieves settings for the trail associated with the current region for your account.
See also: AWS API Documentation
Request Syntax
response = client.describe_trails(
trailNameList=[
'string',
],
includeShadowTrails=True|False
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | 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
|
generate_presigned_url(ClientMethod, Params=None, ExpiresIn=3600, HttpMethod=None)¶Generate a presigned url given a client, its method, and arguments
| Parameters: |
|
|---|---|
| Returns: | The presigned url |
get_event_selectors(**kwargs)¶Describes the settings for the event selectors that you configured for your trail. The information returned for your event selectors includes the following:
For more information, see Logging Data and Management Events for Trails in the AWS CloudTrail User Guide .
See also: AWS API Documentation
Request Syntax
response = client.get_event_selectors(
TrailName='string'
)
| Parameters: | TrailName (string) – [REQUIRED] Specifies the name of the trail or trail ARN. If you specify a trail name, the string must meet the following requirements:
If you specify a trail ARN, it must be in the format:
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{
'TrailARN': 'string',
'EventSelectors': [
{
'ReadWriteType': 'ReadOnly'|'WriteOnly'|'All',
'IncludeManagementEvents': True|False,
'DataResources': [
{
'Type': 'string',
'Values': [
'string',
]
},
]
},
]
}
Response Structure
|
get_paginator(operation_name)¶Create a paginator for an operation.
| Parameters: | operation_name (string) – The operation name. This is the same name
as the method name on the client. For example, if the
method name is create_foo, and you’d normally invoke the
operation as client.create_foo(**kwargs), if the
create_foo operation can be paginated, you can use the
call client.get_paginator("create_foo"). |
|---|---|
| Raises: | OperationNotPageableError – Raised if the operation is not
pageable. You can use the client.can_paginate method to
check if an operation is pageable. |
| Return type: | L{botocore.paginate.Paginator} |
| Returns: | A paginator object. |
get_trail_status(**kwargs)¶Returns a JSON-formatted list of information about the specified trail. Fields include information on delivery errors, Amazon SNS and Amazon S3 errors, and start and stop logging times for each trail. This operation returns trail status from a single region. To return trail status from all regions, you must call the operation on each region.
See also: AWS API Documentation
Request Syntax
response = client.get_trail_status(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] Specifies the name or the CloudTrail ARN of the trail for which you are requesting status. To get the status of a shadow trail (a replication of the trail in another region), you must specify its ARN. The format of a trail ARN is:
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{
'IsLogging': True|False,
'LatestDeliveryError': 'string',
'LatestNotificationError': 'string',
'LatestDeliveryTime': datetime(2015, 1, 1),
'LatestNotificationTime': datetime(2015, 1, 1),
'StartLoggingTime': datetime(2015, 1, 1),
'StopLoggingTime': datetime(2015, 1, 1),
'LatestCloudWatchLogsDeliveryError': 'string',
'LatestCloudWatchLogsDeliveryTime': datetime(2015, 1, 1),
'LatestDigestDeliveryTime': datetime(2015, 1, 1),
'LatestDigestDeliveryError': 'string',
'LatestDeliveryAttemptTime': 'string',
'LatestNotificationAttemptTime': 'string',
'LatestNotificationAttemptSucceeded': 'string',
'LatestDeliveryAttemptSucceeded': 'string',
'TimeLoggingStarted': 'string',
'TimeLoggingStopped': 'string'
}
Response Structure
|
get_waiter(waiter_name)¶list_public_keys(**kwargs)¶Returns all public keys whose private keys were used to sign the digest files within the specified time range. The public key is needed to validate digest files that were signed with its corresponding private key.
Note
CloudTrail uses different private/public key pairs per region. Each digest file is signed with a private key unique to its region. Therefore, when you validate a digest file from a particular region, you must look in the same region for its corresponding public key.
See also: AWS API Documentation
Request Syntax
response = client.list_public_keys(
StartTime=datetime(2015, 1, 1),
EndTime=datetime(2015, 1, 1),
NextToken='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'PublicKeyList': [
{
'Value': b'bytes',
'ValidityStartTime': datetime(2015, 1, 1),
'ValidityEndTime': datetime(2015, 1, 1),
'Fingerprint': 'string'
},
],
'NextToken': 'string'
}
Response Structure
|
Lists the tags for the trail in the current region.
See also: AWS API Documentation
Request Syntax
response = client.list_tags(
ResourceIdList=[
'string',
],
NextToken='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'ResourceTagList': [
{
'ResourceId': 'string',
'TagsList': [
{
'Key': 'string',
'Value': 'string'
},
]
},
],
'NextToken': 'string'
}
Response Structure
|
lookup_events(**kwargs)¶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:
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.
Warning
The rate of lookup requests is limited to one per second per account. If this limit is exceeded, a throttling error occurs.
Warning
Events that occurred during the selected time range will not be available for lookup if CloudTrail logging was not enabled when the events occurred.
See also: AWS API Documentation
Request Syntax
response = 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'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | 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
|
put_event_selectors(**kwargs)¶Configures an event selector for your trail. Use event selectors to specify whether you want your trail to log management and/or data events. 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
GetConsoleOutput and RunInstances API operations occur in your account.RunInstances is a write-only event and it matches your event selector. The trail logs the event.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 Logging Data and Management Events for Trails in the AWS CloudTrail User Guide .
See also: AWS API Documentation
Request Syntax
response = client.put_event_selectors(
TrailName='string',
EventSelectors=[
{
'ReadWriteType': 'ReadOnly'|'WriteOnly'|'All',
'IncludeManagementEvents': True|False,
'DataResources': [
{
'Type': 'string',
'Values': [
'string',
]
},
]
},
]
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'TrailARN': 'string',
'EventSelectors': [
{
'ReadWriteType': 'ReadOnly'|'WriteOnly'|'All',
'IncludeManagementEvents': True|False,
'DataResources': [
{
'Type': 'string',
'Values': [
'string',
]
},
]
},
]
}
Response Structure
|
Removes the specified tags from a trail.
See also: AWS API Documentation
Request Syntax
response = client.remove_tags(
ResourceId='string',
TagsList=[
{
'Key': 'string',
'Value': 'string'
},
]
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {}
Response Structure
|
start_logging(**kwargs)¶Starts the recording of AWS API calls and log file delivery for a trail. For a trail that is enabled in all regions, this operation must be called from the region in which the trail was created. This operation cannot be called on the shadow trails (replicated trails in other regions) of a trail that is enabled in all regions.
See also: AWS API Documentation
Request Syntax
response = client.start_logging(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] Specifies the name or the CloudTrail ARN of the trail for which CloudTrail logs AWS API calls. The format of a trail ARN is:
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{}
Response Structure
|
stop_logging(**kwargs)¶Suspends the recording of AWS API calls and log file delivery for the specified trail. Under most circumstances, there is no need to use this action. You can update a trail without stopping it first. This action is the only way to stop recording. For a trail enabled in all regions, this operation must be called from the region in which the trail was created, or an InvalidHomeRegionException will occur. This operation cannot be called on the shadow trails (replicated trails in other regions) of a trail enabled in all regions.
See also: AWS API Documentation
Request Syntax
response = client.stop_logging(
Name='string'
)
| Parameters: | Name (string) – [REQUIRED] Specifies the name or the CloudTrail ARN of the trail for which CloudTrail will stop logging AWS API calls. The format of a trail ARN is:
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax{}
Response Structure
|
update_trail(**kwargs)¶Updates the settings that specify delivery of log files. Changes to a trail do not require stopping the CloudTrail service. Use this action to designate an existing bucket for log delivery. If the existing bucket has previously been a target for CloudTrail log files, an IAM policy exists for the bucket. UpdateTrail must be called from the region in which the trail was created; otherwise, an InvalidHomeRegionException is thrown.
See also: AWS API Documentation
Request Syntax
response = client.update_trail(
Name='string',
S3BucketName='string',
S3KeyPrefix='string',
SnsTopicName='string',
IncludeGlobalServiceEvents=True|False,
IsMultiRegionTrail=True|False,
EnableLogFileValidation=True|False,
CloudWatchLogsLogGroupArn='string',
CloudWatchLogsRoleArn='string',
KmsKeyId='string'
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'Name': 'string',
'S3BucketName': 'string',
'S3KeyPrefix': 'string',
'SnsTopicName': 'string',
'SnsTopicARN': 'string',
'IncludeGlobalServiceEvents': True|False,
'IsMultiRegionTrail': True|False,
'TrailARN': 'string',
'LogFileValidationEnabled': True|False,
'CloudWatchLogsLogGroupArn': 'string',
'CloudWatchLogsRoleArn': 'string',
'KmsKeyId': 'string'
}
Response Structure
|
The available paginators are:
CloudTrail.Paginator.LookupEvents¶paginator = client.get_paginator('lookup_events')
paginate(**kwargs)¶Creates an iterator that will paginate through responses from CloudTrail.Client.lookup_events().
See also: AWS API Documentation
Request Syntax
response_iterator = paginator.paginate(
LookupAttributes=[
{
'AttributeKey': 'EventId'|'EventName'|'Username'|'ResourceType'|'ResourceName'|'EventSource',
'AttributeValue': 'string'
},
],
StartTime=datetime(2015, 1, 1),
EndTime=datetime(2015, 1, 1),
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
| Parameters: |
|
|---|---|
| Return type: | dict |
| Returns: | Response Syntax {
'Events': [
{
'EventId': 'string',
'EventName': 'string',
'EventTime': datetime(2015, 1, 1),
'EventSource': 'string',
'Username': 'string',
'Resources': [
{
'ResourceType': 'string',
'ResourceName': 'string'
},
],
'CloudTrailEvent': 'string'
},
],
}
Response Structure
|