Skip to content

Instantly share code, notes, and snippets.

View pwmcintyre's full-sized avatar
🥑
golang fever

Peter McIntyre pwmcintyre

🥑
golang fever
View GitHub Profile
@pwmcintyre
pwmcintyre / clone-tables.ts
Created January 21, 2022 03:49
clone all AWS Glue tables to another database
import { Glue } from 'aws-sdk'
const glue = new Glue()
const SourceDatabaseName = "tmp"
const TargetDatabaseName = "ris-reporting"
// begin async
;(async () => {
import { STSClient, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
new STSClient({})
.send(new GetCallerIdentityCommand({}))
.then(console.log)
@pwmcintyre
pwmcintyre / 1 - usage.md
Last active July 13, 2021 11:19
promisify a NodeJS http createServer for testing
# create a test server with canned responses
const server: TestServer = new TestServer(new Response(500, payload), new Response(200, payload))

# wait for it to start
const url = await server.ready()

# use it
fetch(url).then(async res => console.log(await res.json()), console.error)
@pwmcintyre
pwmcintyre / 1-README.md
Last active April 15, 2021 00:46
bulk purge AWS CloudFromation stacks

Simple Stack Purge

Install

npm i

Run

@pwmcintyre
pwmcintyre / makefile
Created November 18, 2020 04:40
start AWS Xray local
xray:
cd /tmp \
&& [ -d "./xray" ] || ( \
curl -O https://s3.dualstack.us-east-2.amazonaws.com/aws-xray-assets.us-east-2/xray-daemon/aws-xray-daemon-macos-3.x.zip \
&& unzip -d xray aws-xray-daemon-macos-3.x.zip \
) \
&& cd xray \
&& ./xray_mac -o -n us-west-2
@pwmcintyre
pwmcintyre / purge.py
Last active September 23, 2022 02:28
purge an s3 bucket of all it's contents, including all object versions
#!/usr/bin/env python
# $ nohup python3 ./purge.py foo-bucket &
import sys
import boto3
# Take the bucket name from command line args
BUCKET = sys.argv[1]
s3 = boto3.resource('s3')
#!/usr/bin/env python3
import boto3
# constants
role_name = 'OrganizationAccountAccessRole'
regions_in_scope = [
'us-east-2',
'us-east-1',
'us-west-1',
'us-west-2',
@pwmcintyre
pwmcintyre / 1-README.md
Last active January 22, 2020 09:22
sample lambda cloudformation

Sample Lambda

Example IAM Role + Lambda

This will fail, you'll need to fix it somehow!

Commands

setup

@pwmcintyre
pwmcintyre / makefile
Created January 1, 2020 22:32
nodejs makefile
SHELL := node
.SHELLFLAGS = -e
.ONESHELL: example
.SILENT: example
example:
const foo = "bar"
console.log( "success", { foo } )

Golang doesn't have try/catch blocks, so you can't simply "throw" an error and hope something will catch it and give you a stack-trace showing you where it came from. Instead we return errors and check them ... but it's important to introduce context before returning ... here's why

Here a simple go program I wrote which doesn't appear to work 🤔

$ go run main.go 
access denied

... it attempts to "process" and "save", but since the "process" function adds no context to the error (it just bubbles it up), the final error is very confusing!