• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

securitywing

How to Query AWS CloudTrail Logs with Athena

by wing

AWS CloudTrail logs all the API calls made to the AWS account. You do not require any tool to view  the last 90 days of events. But if you want to view the logs older than three months you have to setup a S3 bucket to store it  and then you can analyse the logs.  This post aims to show you how you can use AWS Athena to view AWS logs stored in S3 bucket.

You can view the last 90 days of events. Choose an event to view more information about it. To view a complete log of your CloudTrail events, create a trail and then go to your Amazon S3 bucket or CloudWatch Logs.

Create a CloudTrail and store the logs in a S3 bucket

To create a trail, search for CloudTrail and then click on “create trail”. You can use a already created s3 bucket to store the logs or you can opt to create a new bucket while creating the trail.

create aws cloudtrail

Create a table for Athena

Once you finish creating the trail and assign a S3 bucket to it, you need to create a table in Athena.  Click on “event history” in the CloudTrail dashboard and then click on “Run advanced queries in Amazon Athena”.

run advanced queries in amazon athena

Next, select the bucket that you created for storing your logs and then click on “Create Table”.

create a table in Amazon Athena

Run the queries in Athena

Open the Athena dashboard and select the table. Next run the query. For instance to run the query for the event named ‘GetAccountPublicAccessBlock’.

select eventTime, eventName from cloudtrail_logs_your_bucket_name where eventName like ‘GetAccountPublicAccessBlock’

select eventTime, eventName from cloudtrail_logs_your_bucket_name where eventName like ‘DeleteActivity’

select eventTime, eventName from cloudtrail_logs_your_bucket_name where eventType like ‘AwsApiCall’

Note: replace the “your_bucket_name” by your own bucket name.

run query in Athena

Alternative solutions to query logs in S3 buckets

AWS ElasticWolf Client Console-https://aws.amazon.com/tools/aws-elasticwolf-client-console/

S3browser- http://s3browser.com/

Related posts:

  1. How to Install Boto3 for AWS SDK using Anaconda in Windows
  2. 3 Easy Steps to Create EKS(kubernetes) Cluster in AWS
  3. How to Resolve Route 53 Privated Hosted zone from a VPC in a different AWS account
  4. Top 10 Actions to Prevent Cyber Defence Evasion on AWS Cloud

Filed Under: AWS Tagged With: athena, cloudtrail, logs

Primary Sidebar

Please help us sharing

Categories

  • AWS
  • Basics
  • Containers
  • Cryptocurrency
  • Cyber
  • Internet Security and Safety
  • IS Audit
  • IT Security Exams
  • Law & Human Rights
  • Network Security Tips
  • Off Track
  • Social Media Governance
  • Tech Comparisons
  • Tech Stack Suitability
  • Telecom
  • Tutorial

CISSP Sample Test

Take a CISSP Sample Test

CISA Sample Test

CISA IT governance Sample test

Please Follow Us

Contact us for Ads

Go to Contact Form

Search

Footer

Copyrights

Protected by Copyscape Duplicate Content Detection Software

Securitywing.com reserves the copyrights of all of its published articles.No contents of this site is permitted to be published to anywhere else in the Internet.If any contents are found in any other websites, securitywing reserves the rights to file a DMCA complaint. But you have the right to use the link of any relevant article of this site to point from your website if you consider that it might improve the quality of your article.

Tags

audit AWS backup basics browser check cisco cloud computer configuration cyber data database email gmail hsrp ids iis informaiton internet kubernetes linux load balancing malware microsoft network protection redundancy risk router security security tips server social media SSL switch test tools vpn vrrp web webserver website windows wordpress

Copyright © 2010-2025 ·All Rights Reserved · SecurityWing.com