Created
February 7, 2019 20:07
-
-
Save StephenKing/48c10e7483885d1767d6bc6546553209 to your computer and use it in GitHub Desktop.
CloudTrail Athena: Create Partitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# creates Athena partitions for cloudtrail logs (per account, region, year, month) | |
# usage: | |
# ./create-partition.sh my-cloudtrail-bucket 1234566 | pbcopy | |
BUCKET=$1 | |
ACCOUNT=$2 | |
YEAR=$(date +'%Y') | |
echo "ALTER TABLE cloudtrail_logs ADD IF NOT EXISTS" | |
for REGION in $(aws ec2 describe-regions --query "Regions[].{Name:RegionName}" --output text); do | |
for MONTH in $(seq -w 1 12); do | |
echo "PARTITION (account='$ACCOUNT', region='$REGION', year='$YEAR', month='$MONTH') LOCATION 's3://$BUCKET/AWSLogs/$ACCOUNT/CloudTrail/$REGION/$YEAR/$MONTH/'" | |
done | |
done | |
echo ";" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment