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
  • 03:49 (UTC +12:00)
View GitHub Profile
@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 / 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 / correto_unifi.sh
Last active September 30, 2020 02:26
Corrretto JAVA_HOME on Ubuntu 16.04. Replace /etc/init.d/unifi with this!
#!/bin/bash
#
# /etc/init.d/UniFi -- startup script for Ubiquiti UniFi
#
#
### BEGIN INIT INFO
# Provides: unifi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
@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

@cam8001
cam8001 / amazon.url
Created September 9, 2020 23:28
Example .url file, filesystem link which opens in browser
[InternetShortcut]
URL=https://www.amazon.com/
'use strict';
/**
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*/
const AWS = require('aws-sdk');
const url = require('url');
const https = require('https');
@cam8001
cam8001 / user_data.sh
Last active August 6, 2020 00:51
Ubuntu 18.04 User Data, installs ssm for ssh-less login on AWS
#!/bin/bash
apt update && apt upgrade -y
snap install amazon-ssm-agent --classic
ln -fs /usr/share/zoneinfo/Pacific/Auckland /etc/localtime
@cam8001
cam8001 / acm_arn_regex.ts
Last active May 8, 2020 03:43
Regex to validate an AWS Certificate Manager (ACM) certification ARN
// Standalone utility function for checking whether a certificate ARN is valid.
const isValidCertArn = (arnString: string): boolean => {
return /arn:(aws[a-zA-Z-]*)?:acm:[a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1}:\d{12}:certificate\/[a-zA-Z0-9-_]+/.test(
arnString
);
};