Skip to content

Instantly share code, notes, and snippets.

lol no

Cameron Tod cam8001

lol no
  • Wellington, New Zealand
View GitHub Profile
cam8001 /
Last active Jun 26, 2021
Userdata to install Unifi Network (unifi controller) on Ubuntu 20.04 when launching an x86 instance on AWS
# Associate this EIP on launch.
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 / 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: {}
- action: aws:runShellScript
name: backupUnifi
- aws s3 --region ap-southeast-2 sync <your-folder> s3://<your-bucket>
cam8001 /
Last active Jun 18, 2021
Customise AWS cloudshell or Amazon Linux 2 with nice utilities
# 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 / 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",
cam8001 / jq-aws.bash
Created Feb 18, 2021
AWS ip-ranges.json parsing with JQ examples
View jq-aws.bash
# Use jq to parse the published AWS IP ranges.
# Use the file from here:
# Select all Cloudfront nodes homed to Sydney
jq .prefixes[] | select(.service == "CLOUDFRONT") | select(.network_border_group=="ap-southeast-2")
# Find s3 endpoints in Oregon
jq -r '.prefixes[] | select(.region=="us-east-2") | select(.service=="S3") | .ip_prefix' < ip-ranges.json
cam8001 / parseQuery.ts
Created Dec 8, 2020
Typescript timestream parser
View parseQuery.ts
* This file is based on the example from here:
import TimestreamQuery = require('aws-sdk//clients/timestreamquery')
import { QueryResponse } from 'aws-sdk/clients/timestreamquery';
type Datum = TimestreamQuery.Datum;
type DatumList = TimestreamQuery.DatumList;
type ColumnInfo = TimestreamQuery.ColumnInfo;
cam8001 /
Created Nov 4, 2020
Test Cloudfront node performance

Find an IP for a local Cloudfront node.

$ dig

Use a DNS server in the country you are targeting to get an IP for a Cloudfront node there. Eg, for Australia, you can check this list:

$ dig @

Use a combination of:

cam8001 /
Created Nov 1, 2020
Redirect entire s3 bucket

You can use s3 redirection rules to setup redirects.

For example, you might want to redirect one easy to remember domain to some tricky URL.

Create an empty bucket, point your domain to it, then create a rule that catches 404 Not Found and redirects it wherever you need.

New console

cam8001 /
Last active Mar 21, 2021
Trying to figure out what a weird device on my network was - turns out it was my FIL's LG soundbar

Trying to figure out what this thing is:

$ nmap -A -T4 -Pn 2>/dev/null                                                  

Starting Nmap 7.60 ( ) at 2020-10-07 16:34 NZDT
Nmap scan report for
Host is up (0.0038s latency).
Not shown: 997 filtered ports
8008/tcp  open  http            Google Chromecast httpd
cam8001 /
Created Sep 30, 2020
AWS EC2 userdata for Unifi Controller on Ubuntu 16.04. Assumes Correto is installed and Ubiqiuiti repo is added
echo "Updating Unifi..."
systemctl stop unifi
apt update
# Disable interactive prompts for the unifi installer
echo "unifi unifi/has_backup boolean true" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive apt-get install --only-upgrade unifi
# Update the Unifi config for a system using Amazon Corretto instead of OpenJDK
curl > /usr/lib/unifi/bin/unifi.init