Skip to main content

A command-line tool to get valuable information out of AWS CloudTrail

Project description


PyPi Release Build Status

A command-line tool to get valuable information out of AWS CloudTrail


$ pip install trailscraper


# Download some logs (including us-east-1 for global aws services)
$ trailscraper download --bucket some-bucket \
                        --account-id some-account-id \
                        --region some-other-region \
                        --region us-east-1 \
                        --from 'two days ago' \
                        --to 'now' \
# Generate an IAM Policy
$ trailscraper generate-policy
    "Statement": [
            "Action": [
            "Effect": "Allow",
            "Resource": [
            "Action": [
            "Effect": "Allow",
            "Resource": [
    "Version": "2012-10-17"


$ ./go setup   # set up venv, dependencies and tools
$ ./go test    # run some tests
$ ./go check   # run some style checks
$ ./go         # let's see what we can do here


TrailScraper is missing some events
  • Make sure you have logs for the us-east-1 region. Some global AWS services (e.g. Route53, IAM, STS, CloudFront) use this region. For details, check the CloudTrail Documentation
TrailScraper generated actions that aren’t IAM actions

This is totally possible. Unfortunately, there is no good, machine-readable documentation on how CloudTrail events map to IAM actions so TrailScraper is using heuristics to figure out the right actions. These heuristics likely don’t cover all special cases of the AWS world.

This is where you come in: If you find a special case that’s not covered by TrailScraper, please open a new issue or, even better, submit a pull request.

For more details, check out the contribution guide

Click thinks you are in an ASCII environment

Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.

Set environment variables that describe your locale, e.g. :

export LC_ALL=de_DE.utf-8
export LANG=de_DE.utf-8



For details, see


This changelog contains a loose collection of changes in every release including breaking changes to the API.

The format is based on Keep a Changelog



  • Made trailscraper timezone-aware. Until now, trailscraper implicitly treated everything as UTC, meaning relative timestamps (e.g. now, two hours ago) didn’t work properly when filtering logfiles to download or records to generate from. (#39)


  • New command trailscraper last-event-timestamp to get the last known event timestamp.
  • New flag trailscraper download --wait to wait until events for the specified timeframe are found. Useful if you are waiting for CloudTrail to ship logs for a recent operation.



  • Fixed various special cases in mapping CloudTrail to IAM Actions:
    • API Gateway
    • App Stream 2
    • DynamoDB Streams
    • Lex
    • Mechanical Turk
    • S3
    • STS
    • Tagging



  • Ignore record files that can’t be read (e.g. not valid GZIP) in Python 2.7 (was only working in Python 3.* before)
  • Fixed permissions generated for services that include the API version date (e.g. Lambda, CloudFront) (#20)



  • Support for CloudTrail lookup_events API that allows users to generate a policy without downloading logs from an S3 bucket. Note that this API only returns `“create, modify, and delete API calls” <>`__
  • trailscraper download now supports --from and --to flags to specify the timeframe that should be downloaded. Accepts precise (e.g. “2017-10-12”) and relative (e.g. “-2days”) arguments.
  • trailscraper generate-policy now supports --from and --to to filter events to consider for the generated policy. Accepts precise (e.g. “2017-10-12”) and relative (e.g. “-2days”) arguments.
  • Performance optimizations: generate-policy only reads logfiles for the timeframe requested
  • Added --version command line argument


  • Set more flexible dependencies


  • Removed --past-days parameter in trailscraper download. Was replaced by --from and --to (see above)


  • Ignore record files that can’t be read (e.g. not valid GZIP)



  • Support for Python >= 2.7


  • Do not download CloudTrail Logs from S3 if they already exist in the target folder (#9)
  • Removed dependency on fork of the awacs-library to simplify installation and development


  • Bug that led to policy-statements with the same set of actions not being combined properly in some cases (#7)



  • Basic filtering for role-arns when generating policy (#3)


Initial Release


  • Basic feature to download CloudTrail Logs from S3 for certain accounts and timeframe
  • Basic feature to generate IAM Policies from a set of downloaded CloudTrail logs

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for trailscraper, version 0.4.3
Filename, size File type Python version Upload date Hashes
Filename, size trailscraper-0.4.3.tar.gz (14.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page