Skip to content

Instantly share code, notes, and snippets.

View AstroTom's full-sized avatar

Tom Rosenfeld AstroTom

View GitHub Profile
@AstroTom
AstroTom / zfs-sg.sh
Created November 28, 2023 16:06
Create AWS Security Group for ZFS named "zfs-sg"
#!/bin/bash
#
# Create AWS Security Group ZFS security group named "zfs-sg"
#
# sets ports as per https://docs.aws.amazon.com/fsx/latest/OpenZFSGuide/limit-access-security-groups.html
#
# Variables - set your VPC_ID
#
@AstroTom
AstroTom / fsx-sg.sh
Created November 28, 2023 16:01
Create AWS Security Group for FSx named "fsx-sg"
#!/bin/bash
#
# Create AWS Security Group for FSx named "fsx-sg"
# sets ports as per https://docs.aws.amazon.com/fsx/latest/WindowsGuide/limit-access-security-groups.html
#
# Variables - set your VPC_ID
#
VPC_ID=""
@AstroTom
AstroTom / aws-trail-by-region.sh
Last active May 23, 2022 13:59
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.
#
CMD='cloudtrail lookup-events --lookup-attributes AttributeKey=ReadOnly,AttributeValue=false --start-time "2022-03-31, 00:00" --end-time "2022-04-03, 23:59" '
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
@AstroTom
AstroTom / aws-list-by-region.sh
Last active May 23, 2022 14:01
AWS describe resources per regions, or more generally run AWS command in all regions. Based on Script from Avi K.
CMD="eks list-clusters"
CMD="ec2 describe-volumes"
for item in $(aws ec2 describe-regions --output text | awk {'print $4'})
do
echo $item && aws --region $item $CMD
done
@AstroTom
AstroTom / ami-clean.sh
Last active May 10, 2021 11:26 — forked from jdowning/ami-clean.sh
Script to clean up Ubuntu EC2 instance before packaging as an AMI
#!/bin/bash
# This script cleans up your EC2 instance before baking a new AMI.
# this works on Ubuntu (18+)
# Run the following command in a root shell:
#
# bash <(curl -s https://gist.githubusercontent.com/AstroTom/fb0f54d125d38574eae76f57c188c4f0/raw/ami-clean.sh)
function print_green {
echo -e "\e[32m${1}\e[0m"
@AstroTom
AstroTom / send-slow-q.sh
Created April 6, 2021 11:51
Send to SQS a few treks at a time, then wait till Q is empty to send again
#
# send to q a few treks at a time, then wait till Q is empty to send again
#
AWSACCNT=123456789012
Q=https://sqs.eu-west-1.amazonaws.com/$AWSACCNT/prd_navigation_q
Q=https://sqs.eu-west-1.amazonaws.com/$AWSACCNT/stg_navigation_q
QMAX=29 # do not fill Q with more than these
#!/bin/bash
# Tom R.
# based on https://gist.github.com/dukejones/36128decdb1e003ac5d77f5c4523f1f5
# Changed to use ~/.aws/config instead
#
set -e
usage () {
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# You must use 'source' to run this file, otherwise it has no effect
# Alternately, you can put it in .bashrc
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# e.g.
# $ source credentials.sh
#
#
@AstroTom
AstroTom / fix-bucket-acl.sh
Last active March 8, 2021 09:50
Change the ownership of anonymously owned objects in my Amazon S3 bucket
#!/bin/bash
#
# Change the ownership of anonymously owned objects in my Amazon S3 bucket
# see https://aws.amazon.com/premiumsupport/knowledge-center/s3-object-change-anonymous-ownership/
#
# The -r option passed to read command prevents backslash escapes from being interpreted.
# Add IFS= option before read command to prevent leading/trailing whitespace from being trimmed
#
echo 'NOTE: You can ignore the error:
#
# resize an ec2 between t3.medium and GPU g4dn.xlarge
#
AWS_INSTANCE_ID=i-0d286d48c371f57b1
TYPE=g4dn.xlarge
echo This will stop your instance $AWS_INSTANCE_ID to type $TYPE
# find name
echo Name tag is: