Listing CloudTrail Trail Events - AWS SDK for Ruby

Listing CloudTrail Trail Events

This example uses the lookup_events method to list the CloudTrail trail events in the us-west-2 region.

Choose Copy to save the code locally.

Create the file lookup_events.rb. Add the following statement to use the CloudTrail gem of the AWS SDK for Ruby.


Create a function to display information about each event.

Purpose: Lists information about events in AWS CloudTrail. Prerequisites: - You must have an AWS account. For more information, see "How do I create and activate a new Amazon Web Services account" on the AWS Premium Support website. - This code uses default AWS access credentials. For more information, see "Configuring the AWS SDK for Ruby" in the AWS SDK for Ruby Developer Guide. Running the code: To run this code, use RSpec. For example:

Create a CloudTrail client in us-west-2, call lookup_events, and use the show_event function to display information about each event.

Additional information: - As an AWS best practice, grant this code least privilege, or only the permissions required to perform a task. For more information, see "Grant Least Privilege," in the AWS Identity and Access Management User Guide. - This code has not been tested in all AWS Regions. Some AWS services are available only in specific Regions. For more information, see the "AWS Regional Table" on the AWS website. - Running this code outside of the included RSpec tests might result in charges to your AWS account.

See the complete example on GitHub.