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
View GitHub Profile
@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

[
@cam8001
cam8001 / lg-soundbar-network.md
Last active March 21, 2021 07:14
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 10.99.98.97 2>/dev/null                                                  

Starting Nmap 7.60 ( https://nmap.org ) at 2020-10-07 16:34 NZDT
Nmap scan report for 10.99.98.97
Host is up (0.0038s latency).
Not shown: 997 filtered ports
PORT      STATE SERVICE         VERSION
8008/tcp  open  http            Google Chromecast httpd
@cam8001
cam8001 / userdata.sh
Created September 30, 2020 21:33
AWS EC2 userdata for Unifi Controller on Ubuntu 16.04. Assumes Correto is installed and Ubiqiuiti repo is added
#!/bin/bash
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 https://gist.githubusercontent.com/cam8001/585bc721b25c80e185b83269fdb62e4a/raw/de847624ee14b89814c8c759e2559d7871d6c4ce/correto_unifi.sh > /usr/lib/unifi/bin/unifi.init
@cam8001
cam8001 / filter-iam-roles.sh
Created September 29, 2020 23:57
Filter IAM roles showing trust relationship, conditions, and principal
aws iam list-roles | jq '.Roles | .[] | { role_name: .RoleName, action: .AssumeRolePolicyDocument.Statement | .[] | .Action, principal: .AssumeRolePolicyDocument.Statement | .[] | .Principal, condition: .AssumeRolePolicyDocument.Statement | .[] | .Condition }'
@cam8001
cam8001 / ubuntu-ssm-user-data.sh
Last active September 28, 2020 09:17
Ubuntu 16.04 AMI 20180627 and later user data for SSM session manager
#!/bin/bash
apt update && apt upgrade -y
ln -fs /usr/share/zoneinfo/Pacific/Auckland /etc/localtime
systemctl start snap.amazon-ssm-agent.amazon-ssm-agent.service
systemctl enable snap.amazon-ssm-agent.amazon-ssm-agent.service
@cam8001
cam8001 / init-version-systemd.md
Last active September 19, 2020 00:37
/sbin/init: unrecognized option '--version'

If you get an error in some script or whatever like:

/sbin/init: unrecognized option '--version'

This is probably because:

  • /sbin/init is a symlink to /lib/systemd/systemd
  • systemd supports the --version flag, but not if it is called via a symlink ??

So, if possible, replace calls to /sbin/init with calls to systemd instead. Or something