Skip to content

Instantly share code, notes, and snippets.

View cam8001's full-sized avatar
💭
lol no

Cameron Tod cam8001

💭
lol no
  • Amazon Web Services
  • Wellington, New Zealand
  • 12:45 (UTC +12:00)
View GitHub Profile
@cam8001
cam8001 / mac-setup.sh
Last active May 29, 2022 02:06
New Mac setup
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 June 14, 2022 01:58
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 June 26, 2021 00:06
Userdata to install Unifi Network (unifi controller) on Ubuntu 20.04 when launching an x86 instance on AWS
#!/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 June 25, 2021 10:51
SSM Run Command Document for syncing a folder to s3
---
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 January 9, 2024 20:49
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
cam8001 / package.json
Last active April 17, 2021 00:25
tsconfig.json for lambda with typescript
{
"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
cam8001 / jq-aws.bash
Created February 18, 2021 01:26
AWS ip-ranges.json parsing with JQ examples
# Use jq to parse the published AWS IP ranges.
# Use the file from here: https://ip-ranges.amazonaws.com/ip-ranges.json
# 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
cam8001 / parseQuery.ts
Created December 8, 2020 01:30
Typescript timestream parser
/**
* This file is based on the example from here: https://github.com/awslabs/amazon-timestream-tools/blob/master/sample_apps/js/query-example.js
*/
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
cam8001 / curl-tricks.md
Created November 4, 2020 03:49
Test Cloudfront node performance

Find an IP for a local Cloudfront node.

$ dig example.com

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: https://public-dns.info/nameserver/au.html

$ dig example.com @168.1.79.229

Use a combination of:

@cam8001
cam8001 / redirect_s3.md
Created November 1, 2020 23:45
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

[