Skip to content

Instantly share code, notes, and snippets.

@breenie
breenie / README.md
Last active January 26, 2024 15:19
Convert output from cloudformation get-template-summary into an importable file

How to run the script

$ aws cloudformation get-template-summary --template-body file://template.yml > /path/to/summary.json
$ node index.js < /path/to/summary.json > /path/to/resources.json

Fill in the missing values in your the output file and import it.

@breenie
breenie / promise-series.js
Created January 18, 2023 09:44
Execute nodejs promises serially
/**
* Ensures a list of promises run in series
* @param {array} funcs - an array of funcs that return promises
* @returns {object}
*/
const series = (funcs) => funcs.reduce((p, f) => p.then(f), Promise.resolve());
// Thanks go to some random, but forgotten, SE page.
const sane = JSON.stringify("Emdashses should be banned. –")
.replace(
/[^\x20-\x7F]/g,
x => "\\u" + ("000" + x.codePointAt(0).toString(16)).slice(-4)
);
console.log(sane);
// Emdashses should be banned. \u2013
@breenie
breenie / unicodle.js
Created July 19, 2022 10:27
Replace unicode characters with their code point
const sane = JSON.stringify("Emdashses should be banned. –")
.replace(
/[^\x20-\x7F]/g,
x => "\\u" + ("000" + x.codePointAt(0).toString(16)).slice(-4)
);
console.log(sane);
// Emdashses should be banned. \u2013
@breenie
breenie / get-keys.sh
Created May 12, 2021 11:25
Find all AWS access keys in an account
#!/bin/env bash
# Cribbed from somewhere on the internet
for user in $(aws iam list-users --output text | awk '{print $NF}'); do
aws iam list-access-keys --user $user --output text
done
@breenie
breenie / configure-n.sh
Created December 4, 2020 07:16
Configure brew directories for n
sudo mkdir /usr/local/n
sudo chown -R `whoami`:admin /usr/local/n
sudo chown -R `whoami`:admin /usr/local/include/node
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
sudo chown -R `whoami`:admin /usr/local/lib
# sudo chown -R `whoami`:admin /usr/local/lib/dtrace
@breenie
breenie / empty-cloudformation.yml
Created February 12, 2020 12:17
Empty AWS Cloudformation stack
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudFormation exports'
Conditions:
HasNot: !Equals [ 'true', 'false' ]
# dummy (null) resource, never created
Resources:
NullResource:
@breenie
breenie / get-bucket-size.sh
Last active January 27, 2020 11:07
Get AWS S3 bucket usage
# Cribbed from https://serverfault.com/questions/84815/how-can-i-get-the-size-of-an-amazon-s3-bucket
aws s3api list-objects --bucket ${BUCKET} --output json --query "[sum(Contents[].Size), length(Contents[])]"
@breenie
breenie / README.md
Last active December 4, 2019 11:52
Sync AWS S3 buckets across accounts

Sync AWS S3 buckets across accounts

Add the policy.json to the source bucket. Ensure the profile being used has s3:PutObject, s3:GetObject and s3:PutObjectAcl (AWS docs).

Execute:

$ aws s3 sync \
  s3://source \
 s3://target \
@breenie
breenie / README.md
Last active September 3, 2019 09:45
Apex domain S3 redirector

Usage

$ aws cloudformation create-stack \
  --stack-name apex-redirect \
  --region us-east-1 \
  --template-body "$(cat ./apex.yml)" \
  --parameters \
    ParameterKey=DomainName,ParameterValue=example.org