Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
lol no

Cameron Tod cam8001

💭
lol no
  • Wellington, New Zealand
View GitHub Profile
@cam8001
cam8001 / export-contact-list.sh
Created Sep 15, 2022
Export a contact list from SES, with pagination
View export-contact-list.sh
#!/bin/bash
# Specify contact list name here
CONTACT_LIST_NAME=''
OUTPUT_FILE="./contact-list_$CONTACT_LIST_NAME-$(date +%s).csv"
AWS_CLI_COMMAND="aws sesv2 list-contacts --contact-list-name $CONTACT_LIST_NAME --filter FilteredStatus=OPT_IN --page-size 1000 "
function cli_call() {
if [ ! -z NEXT_TOKEN ]; then
cli_output=$($AWS_CLI_COMMAND)
@cam8001
cam8001 / aws-cli.bash
Last active Apr 20, 2022
AWS CLI Snippets
View aws-cli.bash
# Get a list of all SSM managed instances that appear to be online
aws ssm describe-instance-information --filter Key=PingStatus,Values=Online --query "InstanceInformationList[*].{Instance:InstanceId,Name:Name}" --output=text
# Get a list of all IPs for a service in region
# Way 1: using prefix lists
aws ec2 get-managed-prefix-list-entries --prefix-list-id pl-b8a742d1
# Way 2: using ip-ranges.json
curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes | map(select(.region=="ap-southeast-2" and .service=="EC2")) | map(.ip_prefix) | .[]'
@cam8001
cam8001 / userdata.sh
Created Oct 1, 2021
Unifi controller on Ubuntu 20.04 arm64 - AWS userdata
View userdata.sh
echo -e "Running custom Unifi userdata"
AWS_DEFAULT_REGION=ap-southeast-2
# Assoicate an elastic IP
ALLOC_ID=eipalloc-deadbeef
# Set timezone
ln -fs /usr/share/zoneinfo/Pacific/Auckland /etc/localtime
apt-key adv --keyserver keyserver.ubuntu.com --recv 06E85760C0A52C50
@cam8001
cam8001 / userdata.sh
Created Oct 1, 2021
Associate Elastic IP on every boot even with custom AMI (eg for autoscaling)
View userdata.sh
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
@cam8001
cam8001 / mac-setup.sh
Last active May 29, 2022
New Mac setup
View mac-setup.sh
brew install --cask visual-studio-code
brew install --cask iterm2
brew install --cask alfred
brew install --cask istatmenus
brew install --cask hiddenbar
# Shell
echo 'alias l="ls -lashF"' >> ~/.zshrc
@cam8001
cam8001 / shell-setup-ubuntu.sh
Last active Jun 14, 2022
shell-setup-ubuntu.sh
View shell-setup-ubuntu.sh
sudo apt-get -y install git zsh && echo zsh >> ~/.bashrc
echo 'alias l="ls -lash"' >> ~/.zshrc
# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# Install powelevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k &&
sed -i 's/robbyrussell/powerlevel10k\/powerlevel10k/' ~/.zshrc &&
@cam8001
cam8001 / userdata.sh
Last active Jun 26, 2021
Userdata to install Unifi Network (unifi controller) on Ubuntu 20.04 when launching an x86 instance on AWS
View userdata.sh
#!/bin/bash
# Associate this EIP on launch.
ALLOC_ID=eipalloc-0d896138148fed55c
AWS_DEFAULT_REGION=ap-southeast-2
echo "Updating packages..."
# Force grub to update in a silent mode
DEBIAN_FRONTEND=noninteractive apt-get -y -o DPkg::options::="--force-confdef" -o DPkg::options::="--force-confold" -qq --allow-remove-essential --allow-change-held-packages upgrade
# Update packages.
sudo apt-get upgrade -y
@cam8001
cam8001 / ssm-document.yml
Created Jun 25, 2021
SSM Run Command Document for syncing a folder to s3
View ssm-document.yml
---
schemaVersion: '2.2'
description: State Manager Bootstrap Example
parameters: {}
mainSteps:
- action: aws:runShellScript
name: backupUnifi
inputs:
runCommand:
- aws s3 --region ap-southeast-2 sync <your-folder> s3://<your-bucket>
@cam8001
cam8001 / shell-setup.sh
Last active Sep 11, 2022
Customise AWS cloudshell or Amazon Linux 2 with nice utilities
View shell-setup.sh
# Note for Cloudshell, only stuff in your home directory is saved.
# But, Cloudshell already has git and zsh available. So we just install custom binaries to ~/bin and update our path.
# you can whoami == cloudshell-user or $AWS_EXECUTION_ENV==CloudShell to detect cloudshell
# Start zsh on startup. No chsh :(
[[ $AWS_EXECUTION_ENV == "CloudShell" ]] && echo "In CloudShell, no need to install git/zsh" || sudo yum -y install git zsh && echo zsh >> ~/.bashrc
echo 'alias l="ls -lash"' >> ~/.zshrc
@cam8001
cam8001 / package.json
Last active Apr 17, 2021
tsconfig.json for lambda with typescript
View package.json
{
"name": "my-lambda-function",
"version": "1.0.0",
"scripts": {
"build": "tsc && npm run copy-config",
"copy-config": "cp -r configuration/* build/",
"release": "npm run build",
},
"dependencies": {
"aws-lambda": "^1.0.6",