Skip to content

Instantly share code, notes, and snippets.

View huevos-y-bacon's full-sized avatar

Huevos y Bacon huevos-y-bacon

View GitHub Profile
#!/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
@huevos-y-bacon
huevos-y-bacon / stop_instances.py
Created March 8, 2024 13:19
Stop all running EC2 and (optionally) RDS Instances
#!/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

Create Athena DB and table and run queries on AWS Classic Load Balancer logs.

@huevos-y-bacon
huevos-y-bacon / steampipe_commands.sh
Last active January 19, 2024 15:43
Steampipe AWS quick setup command (linux)
#!/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)"
@huevos-y-bacon
huevos-y-bacon / tsv_to_csv.sh
Created January 18, 2024 10:45
Simple script to convert tab separated files to CSV, e.g. DNS Zone files
#!/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=(
@huevos-y-bacon
huevos-y-bacon / aws_org_tree.sh
Last active August 25, 2023 15:52
AWS Organizations - Get Org Tree
#!/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
@huevos-y-bacon
huevos-y-bacon / tf_local_cache_prep.sh
Created August 21, 2023 09:32
Prepare local provider cache for Terraform
#!/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
}
@huevos-y-bacon
huevos-y-bacon / cw_ct_log_insights_query.sql
Created August 4, 2023 10:29
CloudWatch Log Insights Query - CloudTrail
# CloudTrail events: By Service / Role / principalId / etc
fields
eventTime
,eventName
,eventSource
,errorCode
,errorMessage
,userIdentity.principalId as principalId
,userIdentity.sessionContext.sessionIssuer.userName as SESSIONUSERID
,@message
@huevos-y-bacon
huevos-y-bacon / install_granted.sh
Created August 3, 2023 10:34
Install (Common Fate) granted on Mac or (Amazon) Linux
#!/usr/bin/env bash
set -e
# See:
# - https://docs.commonfate.io/granted/getting-started/
# - https://docs.commonfate.io/granted/usage/automatic-config-generation
# Remember to update MY_ORG_NAME!
SSO_URL=https://MY_ORG_NAME.awsapps.com/start/
SSO_ORG=$(echo $SSO_URL | awk -F. '{print $1}' | awk -F/ '{print $NF}')
@huevos-y-bacon
huevos-y-bacon / convert_mp3_to_mp4.sh
Created July 31, 2023 18:01
CONVERT ALL MP3 FILES IN CURRENT DIRECTORY TO MP4 FILES WITH IMAGE AS BACKGROUND
#!/usr/bin/env bash
# CONVERT ALL MP3 FILES IN CURRENT DIRECTORY TO MP4 FILES WITH IMAGE AS BACKGROUND.
# See https://www.bannerbear.com/blog/how-to-convert-audio-to-video-for-youtube-upload-using-ffmpeg/#convert-mp3-to-mp4-with-an-image
# (Tested on MacOS)
ext=mp3
image=image.jpg
mkdir -p mp4 log