Skip to content

Instantly share code, notes, and snippets.

@AstroTom
Last active April 3, 2026 09:52
Show Gist options
  • Select an option

  • Save AstroTom/d160e9f10780d0350a1e4429da6dd96c to your computer and use it in GitHub Desktop.

Select an option

Save AstroTom/d160e9f10780d0350a1e4429da6dd96c to your computer and use it in GitHub Desktop.
AWS collect CloudTrail Events in all regions. More general form of aws-list-by-region.sh that handles quoted args. Need to set the times to your needs. Based on Script from Avi K.
#
# This only collecting the non read-only actions. This will save a lot of time and space.
# If you want all events simple remove the --lookup-attributes and the arg.
#
# To generate the time string use somethng like:
# date -d "2 days ago" +"%Y-%m-%d, %H:%M"
# If you don't limit the time range the command will likely timeout.
#
# Can also add --end-time
#CMD='cloudtrail lookup-events --lookup-attributes AttributeKey=ReadOnly,AttributeValue=false --start-time "2022-03-31, 00:00" "2022-04-03, 23:59" '
DAYS_AGO=1
CMD='cloudtrail lookup-events --lookup-attributes AttributeKey=ReadOnly,AttributeValue=false --start-time "$(date -d "$DAYS_AGO days ago" +"%Y-%m-%d, %H:%M")" '
for region in $(aws ec2 describe-regions --output text | awk {'print $4'})
do
echo $region && eval aws --region $region "$CMD" |tee trail.$region.json.log
done
@AstroTom
Copy link
Copy Markdown
Author

AstroTom commented May 23, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment