Create Athena DB and table and run queries on AWS Classic Load Balancer logs.
This file contains 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
#!/usr/bin/env bash | |
# shellcheck disable=all | |
### Mount the instance store volume to the instance | |
# see: | |
# https://stackoverflow.com/questions/45167717/mounting-a-nvme-disk-on-aws-ec2 | |
# https://gist.github.com/ktheory/3c3616fca42a3716346b | |
# install hdparm and htop |
This file contains 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
#!/usr/bin/env python3 | |
import boto3 | |
ec2 = boto3.resource('ec2') | |
rds = boto3.client('rds') | |
include_rds = False | |
def lambda_handler(event, context): | |
# Stop EC2 instances |
Loop through all EC2 instances (excluding terminated and spot) and enable termination protection
for I in $(aws ec2 describe-instances --query \
'Reservations[].Instances[?(InstanceLifecycle!=`spot` && InstanceState!=terminated)].[InstanceId]' \
--output text); do
aws ec2 modify-instance-attribute --disable-api-termination --instance-id $I;
done
This file contains 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
#!/usr/bin/env bash | |
# shellcheck disable=all | |
exit # don't run this, cat it instead | |
# git clone https://gist.github.com/38b154892c42ce7dde2f42c1eaf65706.git | |
curl -fsSL https://gist.githubusercontent.com/huevos-y-bacon/38b154892c42ce7dde2f42c1eaf65706/raw/c315a7d244f40a85c6f0d10cd78782b83f74e739/steampipe_commands.sh | |
# INSTALL STEAMPIPE AND PLUGINS, configure for eu-west-1 | |
sudo /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/turbot/steampipe/main/install.sh)" |
This file contains 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
#!/usr/bin/env bash | |
# Simple script to convert tab separated files to CSV | |
# E.g. DNS Zone files | |
if [ "$1" != "" ]; then | |
# File name might contain spaces | |
IFS=$'\n' | |
ZONE_FILES=("$1") | |
else ZONE_FILES=( |
This file contains 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
#!/usr/bin/env bash | |
# shellcheck disable=2086,2162,2005,2046,1091 | |
# GET AWS SESSION TOKEN WITH MFA | |
# allowing CLI access to commands without switching to an IAM Role, e.g. for accessing the Well-Architected Tool | |
source colours > /dev/null 2>&1 # import colours script if it exists in the PATH | |
usage(){ | |
echo " |
This file contains 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 | |
# shellcheck disable=SC2086 | |
# This is the same as "set -eux" but also exits on pipefail. | |
# Also see https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3935570#set--e--u--x--o-pipefail | |
set -euo pipefail | |
ROOT=$(aws organizations list-roots | jq -r '.Roots[0].Id') | |
# Function to list accounts and organizational units at a given depth |
This file contains 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
#!/usr/bin/env bash | |
[[ ! "$(uname -s)" == "Darwin" ]] && NOCOLOR=1 # Disable color output if not macOS | |
mkdir -p "${HOME}"/.terraform.d/plugin-cache # Create local plugin cache folder if not exists | |
ecco(){ | |
if [[ -n "${NOCOLOR}" ]]; then echo -e "${*}" | |
else | |
echo -e "\033[0;1;3;32m${*}\033[0m" # echo green bold and italics | |
fi | |
} |
This file contains 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
# CloudTrail events: By Service / Role / principalId / etc | |
fields | |
eventTime | |
,eventName | |
,eventSource | |
,errorCode | |
,errorMessage | |
,userIdentity.principalId as principalId | |
,userIdentity.sessionContext.sessionIssuer.userName as SESSIONUSERID | |
,@message |
NewerOlder