You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.
Class: Aws::CloudTrail::Client
- Inherits:
-
Seahorse::Client::Base
- Object
- Seahorse::Client::Base
- Aws::CloudTrail::Client
- Defined in:
- (unknown)
Overview
An API client for AWS CloudTrail. To construct a client, you need to configure a :region
and :credentials
.
cloudtrail = Aws::CloudTrail::Client.new(
region: region_name,
credentials: credentials,
# ...
)
See #initialize for a full list of supported configuration options.
Region
You can configure a default region in the following locations:
ENV['AWS_REGION']
Aws.config[:region]
Go here for a list of supported regions.
Credentials
Default credentials are loaded automatically from the following locations:
ENV['AWS_ACCESS_KEY_ID']
andENV['AWS_SECRET_ACCESS_KEY']
Aws.config[:credentials]
- The shared credentials ini file at
~/.aws/credentials
(more information) - From an instance profile when running on EC2
You can also construct a credentials object from one of the following classes:
Alternatively, you configure credentials with :access_key_id
and
:secret_access_key
:
# load credentials from disk
creds = YAML.load(File.read('/path/to/secrets'))
Aws::CloudTrail::Client.new(
access_key_id: creds['access_key_id'],
secret_access_key: creds['secret_access_key']
)
Always load your credentials from outside your application. Avoid configuring credentials statically and never commit them to source control.
Instance Attribute Summary
Attributes inherited from Seahorse::Client::Base
Constructor collapse
-
#initialize(options = {}) ⇒ Aws::CloudTrail::Client
constructor
Constructs an API client.
API Operations collapse
-
#add_tags(options = {}) ⇒ Struct
Adds one or more tags to a trail, up to a limit of 50.
-
#create_trail(options = {}) ⇒ Types::CreateTrailResponse
Creates a trail that specifies the settings for delivery of log data to an Amazon S3 bucket.
-
#delete_trail(options = {}) ⇒ Struct
Deletes a trail.
-
#describe_trails(options = {}) ⇒ Types::DescribeTrailsResponse
Retrieves settings for one or more trails associated with the current region for your account.
.
-
#get_event_selectors(options = {}) ⇒ Types::GetEventSelectorsResponse
Describes the settings for the event selectors that you configured for your trail.
-
#get_insight_selectors(options = {}) ⇒ Types::GetInsightSelectorsResponse
Describes the settings for the Insights event selectors that you configured for your trail.
-
#get_trail(options = {}) ⇒ Types::GetTrailResponse
Returns settings information for a specified trail.
.
-
#get_trail_status(options = {}) ⇒ Types::GetTrailStatusResponse
Returns a JSON-formatted list of information about the specified trail.
-
#list_public_keys(options = {}) ⇒ Types::ListPublicKeysResponse
Returns all public keys whose private keys were used to sign the digest files within the specified time range.
-
#list_tags(options = {}) ⇒ Types::ListTagsResponse
Lists the tags for the trail in the current region.
.
-
#list_trails(options = {}) ⇒ Types::ListTrailsResponse
Lists trails that are in the current account.
.
-
#lookup_events(options = {}) ⇒ Types::LookupEventsResponse
Looks up management events or CloudTrail Insights events that are captured by CloudTrail.
-
#put_event_selectors(options = {}) ⇒ Types::PutEventSelectorsResponse
Configures an event selector for your trail.
-
#put_insight_selectors(options = {}) ⇒ Types::PutInsightSelectorsResponse
Lets you enable Insights event logging by specifying the Insights selectors that you want to enable on an existing trail.
-
#remove_tags(options = {}) ⇒ Struct
Removes the specified tags from a trail.
.
-
#start_logging(options = {}) ⇒ Struct
Starts the recording of AWS API calls and log file delivery for a trail.
-
#stop_logging(options = {}) ⇒ Struct
Suspends the recording of AWS API calls and log file delivery for the specified trail.
-
#update_trail(options = {}) ⇒ Types::UpdateTrailResponse
Updates the settings that specify delivery of log files.
Instance Method Summary collapse
-
#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Boolean
Waiters polls an API operation until a resource enters a desired state.
-
#waiter_names ⇒ Array<Symbol>
Returns the list of supported waiters.
Methods inherited from Seahorse::Client::Base
add_plugin, api, #build_request, clear_plugins, define, new, #operation, #operation_names, plugins, remove_plugin, set_api, set_plugins
Methods included from Seahorse::Client::HandlerBuilder
#handle, #handle_request, #handle_response
Constructor Details
#initialize(options = {}) ⇒ Aws::CloudTrail::Client
Constructs an API client.
Instance Method Details
#add_tags(options = {}) ⇒ Struct
Adds one or more tags to a trail, up to a limit of 50. Overwrites an existing tag's value when a new value is specified for an existing tag key. Tag key names must be unique for a trail; you cannot have two keys with the same name but different values. 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 AWS Regions only from the Region in which the trail was created (also known as its home region).
#create_trail(options = {}) ⇒ Types::CreateTrailResponse
Creates a trail that specifies the settings for delivery of log data to an Amazon S3 bucket.
#delete_trail(options = {}) ⇒ Struct
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.
#describe_trails(options = {}) ⇒ Types::DescribeTrailsResponse
Retrieves settings for one or more trails associated with the current region for your account.
#get_event_selectors(options = {}) ⇒ Types::GetEventSelectorsResponse
Describes the settings for the event selectors that you configured for your trail. The information returned for your event selectors includes the following:
-
If your event selector includes read-only events, write-only events, or all events. This applies to both management events and data events.
-
If your event selector includes management events.
-
If your event selector includes data events, the Amazon S3 objects or AWS Lambda functions that you are logging for data events.
For more information, see Logging Data and Management Events for Trails in the AWS CloudTrail User Guide.
#get_insight_selectors(options = {}) ⇒ Types::GetInsightSelectorsResponse
Describes the settings for the Insights event selectors that you configured for your trail. GetInsightSelectors
shows if CloudTrail Insights event logging is enabled on the trail, and if it is, which insight types are enabled. If you run GetInsightSelectors
on a trail that does not have Insights events enabled, the operation throws the exception InsightNotEnabledException
For more information, see Logging CloudTrail Insights Events for Trails in the AWS CloudTrail User Guide.
#get_trail(options = {}) ⇒ Types::GetTrailResponse
Returns settings information for a specified trail.
#get_trail_status(options = {}) ⇒ Types::GetTrailStatusResponse
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.
#list_public_keys(options = {}) ⇒ Types::ListPublicKeysResponse
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.
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.
#list_tags(options = {}) ⇒ Types::ListTagsResponse
Lists the tags for the trail in the current region.
#list_trails(options = {}) ⇒ Types::ListTrailsResponse
Lists trails that are in the current account.
#lookup_events(options = {}) ⇒ Types::LookupEventsResponse
Looks up management events or CloudTrail Insights events that are captured by CloudTrail. You can look up events that occurred in a region within the last 90 days. Lookup supports the following attributes for management events:
-
AWS access key
-
Event ID
-
Event name
-
Event source
-
Read only
-
Resource name
-
Resource type
-
User name
Lookup supports the following attributes for Insights events:
-
Event ID
-
Event name
-
Event source
All attributes are optional. The default number of results returned is 50, with a maximum of 50 possible. The response includes a token that you can use to get the next page of results.
The rate of lookup requests is limited to two per second per account. If this limit is exceeded, a throttling error occurs.
#put_event_selectors(options = {}) ⇒ Types::PutEventSelectorsResponse
Configures an event selector for your trail. 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 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
andRunInstances
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 Logging Data and Management Events for Trails and Limits in AWS CloudTrail in the AWS CloudTrail User Guide.
#put_insight_selectors(options = {}) ⇒ Types::PutInsightSelectorsResponse
Lets you enable Insights event logging by specifying the Insights selectors that you want to enable on an existing trail. You also use PutInsightSelectors
to turn off Insights event logging, by passing an empty list of insight types. In this release, only ApiCallRateInsight
is supported as an Insights selector.
#remove_tags(options = {}) ⇒ Struct
Removes the specified tags from a trail.
#start_logging(options = {}) ⇒ Struct
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.
#stop_logging(options = {}) ⇒ Struct
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.
#update_trail(options = {}) ⇒ Types::UpdateTrailResponse
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.
#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Boolean
Waiters polls an API operation until a resource enters a desired state.
Basic Usage
Waiters will poll until they are succesful, they fail by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop, sleeping between attempts client.waiter_until(waiter_name, params)
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. You configure waiters by passing a block to #wait_until:
# poll for ~25 seconds
client.wait_until(...) do |w|
w.max_attempts = 5
w.delay = 5
end
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success
or :failure
from these callbacks,
it will terminate the waiter.
started_at = Time.now
client.wait_until(...) do |w|
# disable max attempts
w.max_attempts = nil
# poll for 1 hour, instead of a number of attempts
w.before_wait do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
end
Handling Errors
When a waiter is successful, it returns true
. When a waiter
fails, it raises an error. All errors raised extend from
Waiters::Errors::WaiterFailed.
begin
client.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
#waiter_names ⇒ Array<Symbol>
Returns the list of supported waiters. The following table lists the supported waiters and the client method they call:
Waiter Name | Client Method | Default Delay: | Default Max Attempts: |
---|