Hinson's blog

𝕰𝖝𝖈𝖊𝖑𝖑𝖊𝖓𝖈𝖊 𝖎𝖓 𝖈𝖑𝖔𝖚𝖉 𝖆𝖗𝖈𝖍𝖎𝖙𝖊𝖈𝖙𝖚𝖗𝖊 𝖆𝖓𝖉 𝖘𝖊𝖈𝖚𝖗𝖎𝖙𝖞 𝖉𝖔𝖒𝖆𝖎𝖓𝖘 𝖎𝖘 𝖙𝖍𝖊 𝖊𝖙𝖊𝖗𝖓𝖆𝖑 𝖕𝖚𝖗𝖘𝖚𝖎𝖙 𝖔𝖋 𝖒𝖞 𝖕𝖗𝖔𝖋𝖊𝖘𝖘𝖎𝖔𝖓𝖆𝖑 𝖌𝖗𝖔𝖜𝖙𝖍

Automation Exploration: My Journey with AWS CloudTrail, S3, Athena, Jenkins, and Python Matplotlib for Data Visualization

Spread the love



The “tagging” duplicate key error led to empty results from my Athena queries.
The dataset fed into my Python script via the Jenkins pipeline was void of data.


Here’s a concise overview of the steps I took to establish this pipeline::

  1. Create an S3 bucket named s3://xxxxx-aws-cloudtrail-logs-xxxxx for CloudTrail logs storage.
  2. Generated a regional customer-managed KMS key.
  3. Initiated a trail with the following settings:
    multi-region option – selected
    Log file SSE-KMS encryption – enabled
    Select the key created in step 2
    Trail log location set to bucket created in step 1
  4. Create an S3 bucket named s3://xxxxx-user-activitiy-athena-result-xxxxx for CloudTrail logs storage.
  5. Accessed the AWS account as an Admin user and navigated to the AWS Athena portal.
  6. Configured the Query Result Location to point to the bucket established in step 4.
  7. Executed the SQL command CREATE DATABASE IF NOT EXISTS cloudtrail_logs_db; to instantiate a new database.
  8. Utilized an SQL command provided from my GitHub repository to generate a cloudtrail_logs table that matches the structure observed in CloudTrail logs.https://github.com/hihinsonli/Automation_Jenkins/blob/main/aws/athena/cloudtrail_query.sql
  9. Prepared a Python script to test the connectivity between the Jenkins job and the AWS Athena query execution.
    https://github.com/hihinsonli/Automation_Jenkins/blob/main/python/check_athena_query_status.py
  10. Prepared a Python script to visualize CloudTrail data filtered by Athena query.
    https://github.com/hihinsonli/Automation_Jenkins/blob/main/python/visualize_cloudtrail_data.py
  11. Developed a Jenkinsfile shown below Github link:
    https://github.com/hihinsonli/Automation_Jenkins/blob/main/Jenkinsfile/monitor-aws-account-user-activities.Jenkinsfile

If you are interested in viewing my Jenkins job output, feel free to jump on https://automation.hinsonli.com via my Visitor account (username: visitor password: Visitor123)





One thought on “Automation Exploration: My Journey with AWS CloudTrail, S3, Athena, Jenkins, and Python Matplotlib for Data Visualization

Leave a Reply

Your email address will not be published. Required fields are marked *