Skip to content

CloudTrail

The CloudTrail resource provides access to AWS CloudTrail trails.

Usage

from cmq.aws.session import profile

# List all CloudTrail trails
profile().cloudtrail().list()

CloudTrail

Bases: AWSResource

access_key(access_key)

Sets the access key for filtering events.

Parameters:

Name Type Description Default
access_key str

The access key to filter by.

required

Returns:

Name Type Description
cloudtrail cloudtrail

The cloudtrail object for method chaining.

event_name(event_name)

Sets the event name for filtering events.

Parameters:

Name Type Description Default
event_name str

The event name to filter by.

required

Returns:

Name Type Description
cloudtrail cloudtrail

The cloudtrail object for method chaining.

event_source(event_source)

Sets the event source for filtering events.

Parameters:

Name Type Description Default
event_source str

The event source to filter by.

required

Returns:

Name Type Description
cloudtrail cloudtrail

The cloudtrail object for method chaining.

event_time(start_time, end_time)

Sets the event time range for filtering events.

Parameters:

Name Type Description Default
start_time datetime

The start time of the event range.

required
end_time datetime

The end time of the event range.

required

Returns:

Name Type Description
cloudtrail cloudtrail

The cloudtrail object for method chaining.

last(**kwargs)

Sets the number of events to retrieve.

Parameters:

Name Type Description Default
**kwargs dict[str, int]

The keyword arguments for the timedelta.

{}

Returns:

Name Type Description
cloudtrail cloudtrail

The cloudtrail object for method chaining.

resource_name(resource_name)

Sets the resource name for filtering events.

Parameters:

Name Type Description Default
resource_name str

The resource name to filter by.

required

Returns:

Name Type Description
cloudtrail cloudtrail

The cloudtrail object for method chaining.

user_name(user_name)

Sets the user name for filtering events.

Parameters:

Name Type Description Default
user_name str

The user name to filter by.

required

Returns:

Name Type Description
cloudtrail cloudtrail

The cloudtrail object for method chaining.

Inherited from ResourceInterface

Bases: NodeInterface

attr(*args)

Adds a selection operation to the pipeline that will select the specified attributes.

Parameters:

Name Type Description Default
*args list[str]

The attributes to be selected.

()

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

calculate(key, func)

Adds a calculation operation to the pipeline that will calculate a new attribute.

Parameters:

Name Type Description Default
key str

The new key of the attribute.

required
func callable

The calculation function to be used.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

contains(key, value)

Adds a "contains" filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value Any

The value to check for containment.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

ends_with(key, value)

Adds an "ends with" filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value str

The value to check for ending with.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

eq(key, value)

Adds an equality filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value Any

The value to compare against.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

filter(func)

Adds a filter operation to the pipeline that will filter resources based on the given function.

Parameters:

Name Type Description Default
func callable

The filter function to be added.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

gt(key, value)

Adds a "greater than" filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value Any

The value to compare against.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

in_(key, value)

Adds an "in" filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value list

The list of values to check for inclusion.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

lt(key, value)

Adds a "less than" filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value Any

The value to compare against.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

ne(key, value)

Adds a not-equal filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value Any

The value to compare against.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

not_contains(key, value)

Adds a "not contains" filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value Any

The value to check for non-containment.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

starts_with(key, value)

Adds a "starts with" filter to the resource.

Parameters:

Name Type Description Default
key str

The key of the attribute to compare.

required
value str

The value to check for starting with.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

transform(key, func)

Adds a transformation operation to the pipeline that will transform the specified attribute.

Parameters:

Name Type Description Default
key str

The key of the attribute to transform.

required
func callable

The transformation function to be added.

required

Returns:

Name Type Description
ResourceInterface Resource

The updated resource object.

Inherited from Resource

Bases: PagedResourceInterface, ResourcePlugin

csv(flat=False)

Retrieves a list of resources based on the applied filters and returns them in CSV format.

Parameters:

Name Type Description Default
flat bool

Specifies whether the dictionaries should be flattened or not. Defaults to False.

False

Returns:

Name Type Description
str str

List of resources in CSV format.

dict()

Retrieves a dictionary of resources based on the applied filters.

Returns:

Name Type Description
dict dict

A dictionary of resource objects.

do(action)

Performs a custom action on the resources.

Parameters:

Name Type Description Default
action callable

The action to be performed.

required

list()

Retrieves a list of resources based on the applied filters.

Returns:

Name Type Description
list list

A list of resource objects.