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
  • 18:44 (UTC +12:00)
View GitHub Profile
@cam8001
cam8001 / goonsay.sh
Created September 7, 2023 02:17
goonsay.sh
echo " ___________ $@"
echo " (--)[ .]-[ .] /"
echo " (________O__)"
@cam8001
cam8001 / role-instructions.md
Last active May 22, 2023 22:50
`Failed to delete stack: Role <role> is invalid or cannot be assumed` Assume this role from the cli if your cloudformation stack can't delete

Create a role with a trust policy that can be assumed by Cloudformation. Trust policy looks like this:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
 "Effect": "Allow",
@cam8001
cam8001 / http-apigw-log-format.json
Created May 13, 2023 07:43
Logging config for API Gateway JSON format with all variable included
{ "accountId": "$context.accountId", "apiId": "$context.apiId", "authorizer.error": "$context.authorizer.error", "authorizer.principalId": "$context.authorizer.principalId", "authorizer.property": "$context.authorizer.property", "awsEndpointRequestId": "$context.awsEndpointRequestId", "awsEndpointRequestId2": "$context.awsEndpointRequestId2", "customDomain.basePathMatched": "$context.customDomain.basePathMatched", "dataProcessed": "$context.dataProcessed", "domainName": "$context.domainName", "domainPrefix": "$context.domainPrefix", "error.message": "$context.error.message", "error.messageString": "$context.error.messageString", "error.responseType": "$context.error.responseType", "extendedRequestId": "$context.extendedRequestId", "httpMethod": "$context.httpMethod", "identity.accountId": "$context.identity.accountId", "identity.caller": "$context.identity.caller", "identity.cognitoAuthenticationProvider": "$context.identity.cognitoAuthenticationProvider", "identity.cognitoAuthenticationType": "$context.ident
@cam8001
cam8001 / .zshrc
Created May 6, 2023 02:29
aws cli autocompletions for zsh
# after doing `brew install awscli`, add the following to the bottom of your .zshrc:
autoload bashcompinit && bashcompinit
source /opt/homebrew/share/zsh/site-functions/aws_zsh_completer.sh
@cam8001
cam8001 / etcher.md
Created February 6, 2023 20:55
balena-etcher-cli
# connect your flash drive
# make sure it is visible to etcher

$ balena util available-drives
@cam8001
cam8001 / service-regions.sh
Last active December 20, 2023 19:41
One liner to get list of services keyed to AWS region
#!/bin/bash
curl -s 'https://api.regional-table.region-services.aws.a2z.com/index.json' \
| jq '.prices[] | .attributes | .["aws:region"], .["aws:serviceName"]' \
| sed '$!N;s/\n/,/'
@cam8001
cam8001 / export-contact-list.sh
Created September 15, 2022 00:18
Export a contact list from SES, with pagination
#!/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 April 20, 2022 06:02
AWS CLI Snippets
# 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 October 1, 2021 09:41
Unifi controller on Ubuntu 20.04 arm64 - AWS userdata
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 October 1, 2021 09:38
Associate Elastic IP on every boot even with custom AMI (eg for autoscaling)
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