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 show all
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'] and ENV['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

#config, #handlers

Constructor collapse

API Operations collapse

Instance Method Summary collapse

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.

Options Hash (options):

  • :access_key_id (String)

    Used to set credentials statically. See Plugins::RequestSigner for more details.

  • :active_endpoint_cache (Boolean)

    When set to true, a thread polling for endpoints will be running in the background every 60 secs (default). Defaults to false. See Plugins::EndpointDiscovery for more details.

  • :convert_params (Boolean) — default: true

    When true, an attempt is made to coerce request parameters into the required types. See Plugins::ParamConverter for more details.

  • :credentials (required, Credentials)

    Your AWS credentials. The following locations will be searched in order for credentials:

    • :access_key_id, :secret_access_key, and :session_token options
    • ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']
    • HOME/.aws/credentials shared credentials file
    • EC2 instance profile credentials See Plugins::RequestSigner for more details.
  • :disable_host_prefix_injection (Boolean)

    Set to true to disable SDK automatically adding host prefix to default service endpoint when available. See Plugins::EndpointPattern for more details.

  • :endpoint (String)

    A default endpoint is constructed from the :region. See Plugins::RegionalEndpoint for more details.

  • :endpoint_cache_max_entries (Integer)

    Used for the maximum size limit of the LRU cache storing endpoints data for endpoint discovery enabled operations. Defaults to 1000. See Plugins::EndpointDiscovery for more details.

  • :endpoint_cache_max_threads (Integer)

    Used for the maximum threads in use for polling endpoints to be cached, defaults to 10. See Plugins::EndpointDiscovery for more details.

  • :endpoint_cache_poll_interval (Integer)

    When :endpoint_discovery and :active_endpoint_cache is enabled, Use this option to config the time interval in seconds for making requests fetching endpoints information. Defaults to 60 sec. See Plugins::EndpointDiscovery for more details.

  • :endpoint_discovery (Boolean)

    When set to true, endpoint discovery will be enabled for operations when available. Defaults to false. See Plugins::EndpointDiscovery for more details.

  • :http_continue_timeout (Float) — default: 1

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_idle_timeout (Integer) — default: 5

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_open_timeout (Integer) — default: 15

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_proxy (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_read_timeout (Integer) — default: 60

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_wire_trace (Boolean) — default: false

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :log_level (Symbol) — default: :info

    The log level to send messages to the logger at. See Plugins::Logging for more details.

  • :log_formatter (Logging::LogFormatter)

    The log formatter. Defaults to Seahorse::Client::Logging::Formatter.default. See Plugins::Logging for more details.

  • :logger (Logger) — default: nil

    The Logger instance to send log messages to. If this option is not set, logging will be disabled. See Plugins::Logging for more details.

  • :profile (String)

    Used when loading credentials from the shared credentials file at HOME/.aws/credentials. When not specified, 'default' is used. See Plugins::RequestSigner for more details.

  • :raise_response_errors (Boolean) — default: true

    When true, response errors are raised. See Seahorse::Client::Plugins::RaiseResponseErrors for more details.

  • :region (required, String)

    The AWS region to connect to. The region is used to construct the client endpoint. Defaults to ENV['AWS_REGION']. Also checks AMAZON_REGION and AWS_DEFAULT_REGION. See Plugins::RegionalEndpoint for more details.

  • :retry_limit (Integer) — default: 3

    The maximum number of times to retry failed requests. Only ~ 500 level server errors and certain ~ 400 level client errors are retried. Generally, these are throttling errors, data checksum errors, networking errors, timeout errors and auth errors from expired credentials. See Plugins::RetryErrors for more details.

  • :secret_access_key (String)

    Used to set credentials statically. See Plugins::RequestSigner for more details.

  • :session_token (String)

    Used to set credentials statically. See Plugins::RequestSigner for more details.

  • :simple_json (Boolean) — default: false

    Disables request parameter conversion, validation, and formatting. Also disable response data type conversions. This option is useful when you want to ensure the highest level of performance by avoiding overhead of walking request parameters and response data structures.

    When :simple_json is enabled, the request parameters hash must be formatted exactly as the DynamoDB API expects. See Plugins::Protocols::JsonRpc for more details.

  • :ssl_ca_bundle (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :ssl_ca_directory (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :ssl_ca_store (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :ssl_verify_peer (Boolean) — default: true

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :stub_responses (Boolean) — default: false

    Causes the client to return stubbed responses. By default fake responses are generated and returned. You can specify the response data to return or errors to raise by calling Aws::ClientStubs#stub_responses. See Aws::ClientStubs for more information.

    Please note When response stubbing is enabled, no HTTP requests are made, and retries are disabled. See Plugins::StubResponses for more details.

  • :validate_params (Boolean) — default: true

    When true, request parameters are validated before sending the request. See Plugins::ParamValidator for more details.

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).

Examples:

Request syntax with placeholder values


resp = client.add_tags({
  resource_id: "String", # required
  tags_list: [
    {
      key: "String", # required
      value: "String",
    },
  ],
})

Options Hash (options):

  • :resource_id (required, String)

    Specifies the ARN of the trail to which one or more tags will be added. The format of a trail ARN is:

    arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

  • :tags_list (Array<Types::Tag>)

    Contains a list of CloudTrail tags, up to a limit of 50

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#create_trail(options = {}) ⇒ Types::CreateTrailResponse

Creates a trail that specifies the settings for delivery of log data to an Amazon S3 bucket.

Examples:

Request syntax with placeholder values


resp = client.create_trail({
  name: "String", # required
  s3_bucket_name: "String", # required
  s3_key_prefix: "String",
  sns_topic_name: "String",
  include_global_service_events: false,
  is_multi_region_trail: false,
  enable_log_file_validation: false,
  cloud_watch_logs_log_group_arn: "String",
  cloud_watch_logs_role_arn: "String",
  kms_key_id: "String",
  is_organization_trail: false,
  tags_list: [
    {
      key: "String", # required
      value: "String",
    },
  ],
})

Response structure


resp.name #=> String
resp.s3_bucket_name #=> String
resp.s3_key_prefix #=> String
resp.sns_topic_name #=> String
resp.sns_topic_arn #=> String
resp.include_global_service_events #=> true/false
resp.is_multi_region_trail #=> true/false
resp.trail_arn #=> String
resp.log_file_validation_enabled #=> true/false
resp.cloud_watch_logs_log_group_arn #=> String
resp.cloud_watch_logs_role_arn #=> String
resp.kms_key_id #=> String
resp.is_organization_trail #=> true/false

Options Hash (options):

  • :name (required, String)

    Specifies the name of the trail. The name 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)

  • :s3_bucket_name (required, String)

    Specifies the name of the Amazon S3 bucket designated for publishing log files. See Amazon S3 Bucket Naming Requirements.

  • :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.

  • :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.

  • :include_global_service_events (Boolean)

    Specifies whether the trail is publishing events from global services such as IAM to the log files.

  • :is_multi_region_trail (Boolean)

    Specifies whether the trail is created in the current region or in all regions. The default is false, which creates a trail only in the region where you are signed in. As a best practice, consider creating trails that log events in all regions.

  • :enable_log_file_validation (Boolean)

    Specifies whether log file integrity validation is enabled. The default is false.

    When you disable log file integrity validation, the chain of digest files is broken after one hour. CloudTrail will not create digest files for log files that were delivered during a period in which log file integrity validation was disabled. For example, if you enable log file integrity validation at noon on January 1, disable it at noon on January 2, and re-enable it at noon on January 10, digest files will not be created for the log files delivered from noon on January 2 to noon on January 10. The same applies whenever you stop CloudTrail logging or delete a 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.

  • :cloud_watch_logs_role_arn (String)

    Specifies the role for the CloudWatch Logs endpoint to assume to write to a user\'s log group.

  • :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.

    Examples:

    • alias/MyAliasName

    • arn:aws:kms:us-east-2:123456789012:alias/MyAliasName

    • arn:aws:kms:us-east-2:123456789012:key/12345678-1234-1234-1234-123456789012

    • 12345678-1234-1234-1234-123456789012

  • :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.

  • :tags_list (Array<Types::Tag>)

    A list of tags.

Returns:

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.delete_trail({
  name: "String", # required
})

Options Hash (options):

  • :name (required, String)

    Specifies the name or the CloudTrail ARN of the trail to be deleted. The format of a trail ARN is: arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#describe_trails(options = {}) ⇒ Types::DescribeTrailsResponse

Retrieves settings for one or more trails associated with the current region for your account.

Examples:

Request syntax with placeholder values


resp = client.describe_trails({
  trail_name_list: ["String"],
  include_shadow_trails: false,
})

Response structure


resp.trail_list #=> Array
resp.trail_list[0].name #=> String
resp.trail_list[0].s3_bucket_name #=> String
resp.trail_list[0].s3_key_prefix #=> String
resp.trail_list[0].sns_topic_name #=> String
resp.trail_list[0].sns_topic_arn #=> String
resp.trail_list[0].include_global_service_events #=> true/false
resp.trail_list[0].is_multi_region_trail #=> true/false
resp.trail_list[0].home_region #=> String
resp.trail_list[0].trail_arn #=> String
resp.trail_list[0].log_file_validation_enabled #=> true/false
resp.trail_list[0].cloud_watch_logs_log_group_arn #=> String
resp.trail_list[0].cloud_watch_logs_role_arn #=> String
resp.trail_list[0].kms_key_id #=> String
resp.trail_list[0].has_custom_event_selectors #=> true/false
resp.trail_list[0].has_insight_selectors #=> true/false
resp.trail_list[0].is_organization_trail #=> true/false

Options Hash (options):

  • :trail_name_list (Array<String>)

    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-2: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.

    If one or more trail names are specified, information is returned only if the names match the names of trails belonging only to the current region. To return information about a trail in another region, you must specify its trail ARN.

  • :include_shadow_trails (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, or in the case of an organization trail, the replication of an organization trail in member accounts. If you do not include shadow trails, organization trails in a member account and region replication trails will not be returned. The default is true.

Returns:

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.get_event_selectors({
  trail_name: "String", # required
})

Response structure


resp.trail_arn #=> String
resp.event_selectors #=> Array
resp.event_selectors[0].read_write_type #=> String, one of "ReadOnly", "WriteOnly", "All"
resp.event_selectors[0].include_management_events #=> true/false
resp.event_selectors[0].data_resources #=> Array
resp.event_selectors[0].data_resources[0].type #=> String
resp.event_selectors[0].data_resources[0].values #=> Array
resp.event_selectors[0].data_resources[0].values[0] #=> String
resp.event_selectors[0].exclude_management_event_sources #=> Array
resp.event_selectors[0].exclude_management_event_sources[0] #=> String

Options Hash (options):

  • :trail_name (required, 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 not valid.

    • 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-2:123456789012:trail/MyTrail

Returns:

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.get_insight_selectors({
  trail_name: "String", # required
})

Response structure


resp.trail_arn #=> String
resp.insight_selectors #=> Array
resp.insight_selectors[0].insight_type #=> String, one of "ApiCallRateInsight"

Options Hash (options):

  • :trail_name (required, 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 not valid.

    • 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-2:123456789012:trail/MyTrail

Returns:

See Also:

#get_trail(options = {}) ⇒ Types::GetTrailResponse

Returns settings information for a specified trail.

Examples:

Request syntax with placeholder values


resp = client.get_trail({
  name: "String", # required
})

Response structure


resp.trail.name #=> String
resp.trail.s3_bucket_name #=> String
resp.trail.s3_key_prefix #=> String
resp.trail.sns_topic_name #=> String
resp.trail.sns_topic_arn #=> String
resp.trail.include_global_service_events #=> true/false
resp.trail.is_multi_region_trail #=> true/false
resp.trail.home_region #=> String
resp.trail.trail_arn #=> String
resp.trail.log_file_validation_enabled #=> true/false
resp.trail.cloud_watch_logs_log_group_arn #=> String
resp.trail.cloud_watch_logs_role_arn #=> String
resp.trail.kms_key_id #=> String
resp.trail.has_custom_event_selectors #=> true/false
resp.trail.has_insight_selectors #=> true/false
resp.trail.is_organization_trail #=> true/false

Options Hash (options):

  • :name (required, String)

    The name or the Amazon Resource Name (ARN) of the trail for which you want to retrieve settings information.

Returns:

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.get_trail_status({
  name: "String", # required
})

Response structure


resp.is_logging #=> true/false
resp.latest_delivery_error #=> String
resp.latest_notification_error #=> String
resp.latest_delivery_time #=> Time
resp.latest_notification_time #=> Time
resp.start_logging_time #=> Time
resp.stop_logging_time #=> Time
resp.latest_cloud_watch_logs_delivery_error #=> String
resp.latest_cloud_watch_logs_delivery_time #=> Time
resp.latest_digest_delivery_time #=> Time
resp.latest_digest_delivery_error #=> String
resp.latest_delivery_attempt_time #=> String
resp.latest_notification_attempt_time #=> String
resp.latest_notification_attempt_succeeded #=> String
resp.latest_delivery_attempt_succeeded #=> String
resp.time_logging_started #=> String
resp.time_logging_stopped #=> String

Options Hash (options):

  • :name (required, String)

    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:

    arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

Returns:

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.list_public_keys({
  start_time: Time.now,
  end_time: Time.now,
  next_token: "String",
})

Response structure


resp.public_key_list #=> Array
resp.public_key_list[0].value #=> IO
resp.public_key_list[0].validity_start_time #=> Time
resp.public_key_list[0].validity_end_time #=> Time
resp.public_key_list[0].fingerprint #=> String
resp.next_token #=> String

Options Hash (options):

  • :start_time (Time)

    Optionally specifies, in UTC, the start of the time range to look up public keys for CloudTrail digest files. If not specified, the current time is used, and the current public key is returned.

  • :end_time (Time)

    Optionally specifies, in UTC, the end of the time range to look up public keys for CloudTrail digest files. If not specified, the current time is used.

  • :next_token (String)

    Reserved for future use.

Returns:

See Also:

#list_tags(options = {}) ⇒ Types::ListTagsResponse

Lists the tags for the trail in the current region.

Examples:

Request syntax with placeholder values


resp = client.list_tags({
  resource_id_list: ["String"], # required
  next_token: "String",
})

Response structure


resp.resource_tag_list #=> Array
resp.resource_tag_list[0].resource_id #=> String
resp.resource_tag_list[0].tags_list #=> Array
resp.resource_tag_list[0].tags_list[0].key #=> String
resp.resource_tag_list[0].tags_list[0].value #=> String
resp.next_token #=> String

Options Hash (options):

  • :resource_id_list (required, Array<String>)

    Specifies a list of trail ARNs whose tags will be listed. The list has a limit of 20 ARNs. The format of a trail ARN is:

    arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

  • :next_token (String)

    Reserved for future use.

Returns:

See Also:

#list_trails(options = {}) ⇒ Types::ListTrailsResponse

Lists trails that are in the current account.

Examples:

Request syntax with placeholder values


resp = client.list_trails({
  next_token: "String",
})

Response structure


resp.trails #=> Array
resp.trails[0].trail_arn #=> String
resp.trails[0].name #=> String
resp.trails[0].home_region #=> String
resp.next_token #=> String

Options Hash (options):

  • :next_token (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.

Returns:

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.lookup_events({
  lookup_attributes: [
    {
      attribute_key: "EventId", # required, accepts EventId, EventName, ReadOnly, Username, ResourceType, ResourceName, EventSource, AccessKeyId
      attribute_value: "String", # required
    },
  ],
  start_time: Time.now,
  end_time: Time.now,
  event_category: "insight", # accepts insight
  max_results: 1,
  next_token: "NextToken",
})

Response structure


resp.events #=> Array
resp.events[0].event_id #=> String
resp.events[0].event_name #=> String
resp.events[0].read_only #=> String
resp.events[0].access_key_id #=> String
resp.events[0].event_time #=> Time
resp.events[0].event_source #=> String
resp.events[0].username #=> String
resp.events[0].resources #=> Array
resp.events[0].resources[0].resource_type #=> String
resp.events[0].resources[0].resource_name #=> String
resp.events[0].cloud_trail_event #=> String
resp.next_token #=> String

Options Hash (options):

  • :lookup_attributes (Array<Types::LookupAttribute>)

    Contains a list of lookup attributes. Currently the list can contain only one item.

  • :start_time (Time)

    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.

  • :end_time (Time)

    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.

  • :event_category (String)

    Specifies the event category. If you do not specify an event category, events of the category are not returned in the response. For example, if you do not specify insight as the value of EventCategory, no Insights events are returned.

  • :max_results (Integer)

    The number of events to return. Possible values are 1 through 50. The default is 50.

  • :next_token (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.

Returns:

See Also:

#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

  1. You create an event selector for a trail and specify that you want write-only events.

  2. The EC2 GetConsoleOutput and RunInstances API operations occur in your account.

  3. CloudTrail evaluates whether the events match your event selectors.

  4. The RunInstances is a write-only event and it matches your event selector. The trail logs the event.

  5. 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.

Examples:

Request syntax with placeholder values


resp = client.put_event_selectors({
  trail_name: "String", # required
  event_selectors: [ # required
    {
      read_write_type: "ReadOnly", # accepts ReadOnly, WriteOnly, All
      include_management_events: false,
      data_resources: [
        {
          type: "String",
          values: ["String"],
        },
      ],
      exclude_management_event_sources: ["String"],
    },
  ],
})

Response structure


resp.trail_arn #=> String
resp.event_selectors #=> Array
resp.event_selectors[0].read_write_type #=> String, one of "ReadOnly", "WriteOnly", "All"
resp.event_selectors[0].include_management_events #=> true/false
resp.event_selectors[0].data_resources #=> Array
resp.event_selectors[0].data_resources[0].type #=> String
resp.event_selectors[0].data_resources[0].values #=> Array
resp.event_selectors[0].data_resources[0].values[0] #=> String
resp.event_selectors[0].exclude_management_event_sources #=> Array
resp.event_selectors[0].exclude_management_event_sources[0] #=> String

Options Hash (options):

  • :trail_name (required, 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-2:123456789012:trail/MyTrail

  • :event_selectors (required, Array<Types::EventSelector>)

    Specifies the settings for your event selectors. You can configure up to five event selectors for a trail.

Returns:

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.put_insight_selectors({
  trail_name: "String", # required
  insight_selectors: [ # required
    {
      insight_type: "ApiCallRateInsight", # accepts ApiCallRateInsight
    },
  ],
})

Response structure


resp.trail_arn #=> String
resp.insight_selectors #=> Array
resp.insight_selectors[0].insight_type #=> String, one of "ApiCallRateInsight"

Options Hash (options):

  • :trail_name (required, String)

    The name of the CloudTrail trail for which you want to change or add Insights selectors.

  • :insight_selectors (required, Array<Types::InsightSelector>)

    A JSON string that contains the insight types you want to log on a trail. In this release, only ApiCallRateInsight is supported as an insight type.

Returns:

See Also:

#remove_tags(options = {}) ⇒ Struct

Removes the specified tags from a trail.

Examples:

Request syntax with placeholder values


resp = client.remove_tags({
  resource_id: "String", # required
  tags_list: [
    {
      key: "String", # required
      value: "String",
    },
  ],
})

Options Hash (options):

  • :resource_id (required, String)

    Specifies the ARN of the trail from which tags should be removed. The format of a trail ARN is:

    arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

  • :tags_list (Array<Types::Tag>)

    Specifies a list of tags to be removed.

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.start_logging({
  name: "String", # required
})

Options Hash (options):

  • :name (required, String)

    Specifies the name or the CloudTrail ARN of the trail for which CloudTrail logs AWS API calls. The format of a trail ARN is:

    arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.stop_logging({
  name: "String", # required
})

Options Hash (options):

  • :name (required, String)

    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:

    arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#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.

Examples:

Request syntax with placeholder values


resp = client.update_trail({
  name: "String", # required
  s3_bucket_name: "String",
  s3_key_prefix: "String",
  sns_topic_name: "String",
  include_global_service_events: false,
  is_multi_region_trail: false,
  enable_log_file_validation: false,
  cloud_watch_logs_log_group_arn: "String",
  cloud_watch_logs_role_arn: "String",
  kms_key_id: "String",
  is_organization_trail: false,
})

Response structure


resp.name #=> String
resp.s3_bucket_name #=> String
resp.s3_key_prefix #=> String
resp.sns_topic_name #=> String
resp.sns_topic_arn #=> String
resp.include_global_service_events #=> true/false
resp.is_multi_region_trail #=> true/false
resp.trail_arn #=> String
resp.log_file_validation_enabled #=> true/false
resp.cloud_watch_logs_log_group_arn #=> String
resp.cloud_watch_logs_role_arn #=> String
resp.kms_key_id #=> String
resp.is_organization_trail #=> true/false

Options Hash (options):

  • :name (required, String)

    Specifies the name of the trail or trail ARN. If Name is 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 Name is a trail ARN, it must be in the format:

    arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail

  • :s3_bucket_name (String)

    Specifies the name of the Amazon S3 bucket designated for publishing log files. See Amazon S3 Bucket Naming Requirements.

  • :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.

  • :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.

  • :include_global_service_events (Boolean)

    Specifies whether the trail is publishing events from global services such as IAM to the log files.

  • :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.

  • :enable_log_file_validation (Boolean)

    Specifies whether log file validation is enabled. The default is false.

    When you disable log file integrity validation, the chain of digest files is broken after one hour. CloudTrail will not create digest files for log files that were delivered during a period in which log file integrity validation was disabled. For example, if you enable log file integrity validation at noon on January 1, disable it at noon on January 2, and re-enable it at noon on January 10, digest files will not be created for the log files delivered from noon on January 2 to noon on January 10. The same applies whenever you stop CloudTrail logging or delete a 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.

  • :cloud_watch_logs_role_arn (String)

    Specifies the role for the CloudWatch Logs endpoint to assume to write to a user\'s log group.

  • :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.

    Examples:

    • alias/MyAliasName

    • arn:aws:kms:us-east-2:123456789012:alias/MyAliasName

    • arn:aws:kms:us-east-2:123456789012:key/12345678-1234-1234-1234-123456789012

    • 12345678-1234-1234-1234-123456789012

  • :is_organization_trail (Boolean)

    Specifies whether the trail is applied to 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. If the trail is not an organization trail and this is set to true, the trail will be created in all AWS accounts that belong to the organization. If the trail is an organization trail and this is set to false, the trail will remain in the current AWS account but be deleted from all member accounts in the organization.

Returns:

See Also:

#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

Parameters:

  • waiter_name (Symbol)

    The name of the waiter. See #waiter_names for a full list of supported waiters.

  • params (Hash) (defaults to: {})

    Additional request parameters. See the #waiter_names for a list of supported waiters and what request they call. The called request determines the list of accepted parameters.

Yield Parameters:

Returns:

  • (Boolean)

    Returns true if the waiter was successful.

Raises:

  • (Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

  • (Errors::TooManyAttemptsError)

    Raised when the configured maximum number of attempts have been made, and the waiter is not yet successful.

  • (Errors::UnexpectedError)

    Raised when an error is encounted while polling for a resource that is not expected.

  • (Errors::NoSuchWaiterError)

    Raised when you request to wait for an unknown state.

#waiter_namesArray<Symbol>

Returns the list of supported waiters. The following table lists the supported waiters and the client method they call:

Waiter NameClient MethodDefault Delay:Default Max Attempts:

Returns:

  • (Array<Symbol>)

    the list of supported waiters.