Skip to content

Instantly share code, notes, and snippets.

@anamorph
Created October 30, 2015 20:45
Show Gist options
  • Save anamorph/6c62bb992ca795952399 to your computer and use it in GitHub Desktop.
Save anamorph/6c62bb992ca795952399 to your computer and use it in GitHub Desktop.
# Create trails in all AWS standard regions with the AWS CLI and Linux.
# Create trails in all AWS standard regions with the AWS CLI and Linux.
SCRIPTNAME=$0
if [ -z $3 ]
then
echo "$SCRIPTNAME is missing parameters.
Usage: $SCRIPTNAME bucket region profile
Example: $SCRIPTNAME my-cloudtrail-bucket eu-west-1 default"
else
CLOUDTRAIL_S3_BUCKET=$1
REGION_FOR_GLOBAL_EVENTS=$2
PROFILE=$3
regionlist=($(aws ec2 describe-regions --query Regions[*].RegionName --output text))
for region in "${regionlist[@]}"
do
if [ $region = $REGION_FOR_GLOBAL_EVENTS ]
then
aws --profile $PROFILE --region $region cloudtrail create-trail --name $region --s3-bucket-name $CLOUDTRAIL_S3_BUCKET --include-global-service-events --output table
else
aws --profile $PROFILE --region $region cloudtrail create-trail --name $region --s3-bucket-name $CLOUDTRAIL_S3_BUCKET --no-include-global-service-events --output table
fi
aws --profile $PROFILE --region $region cloudtrail start-logging --name $region --output table
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment