Skip to content

Instantly share code, notes, and snippets.

@tomcant
tomcant / configure-s3-lambda-notification.sh
Last active October 8, 2024 14:42
Configure S3 Lambda notifications
#!/usr/bin/env bash
##
# This configures an S3 bucket ObjectCreated notification for the given Lambda
# function so that when a file is uploaded the Lambda function is invoked. This
# is useful when the bucket is not defined in the same CloudFormation template
# as the function. CloudFormation cannot setup the notification in this case.
#
# Note that the AWS CLI is used and will require valid AWS credentials for the
# account containing the resources. The 'jq' JSON processor is also required
@tomcant
tomcant / git-dmerged-alias
Created October 18, 2019 12:36
Put this in ~/.gitconfig to create the "dmerged" Git alias. This deletes local branches that have been merged.
[alias]
dmerged = "!git branch --merged | grep -v '\\*\\|master' | xargs -n 1 git branch -d"
@tomcant
tomcant / fastly-cache-warmer.js
Last active April 5, 2024 08:03
Fastly Cache Warmer
'use strict';
['START_URL', 'PATH_REGEX'].forEach((env) => {
if (!(env in process.env)) {
console.error(`The '${env}' environment variable is missing.`);
process.exit(1);
}
});
let SimpleCrawler = require('simplecrawler');
version: "3.7"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
ports:
- 9200
- 9300
environment:
- discovery.type=single-node
@tomcant
tomcant / assume-role.json
Last active March 4, 2020 09:36
Acquire temporary AWS credentials for an IAM role using the STS AssumeRole operation.
{
"root": {
"access_key_id": "acceaccess_key_idss",
"secret_access_key": "secret_access_key"
},
"roles": {
"SomeRole": {
"arn": "arn:aws:iam::ACCOUNT_ID:role/SomeRole",
"external_id": "external_id"
},
@tomcant
tomcant / update-workspace-version.sh
Created August 26, 2020 16:05
Update the version of Terraform used by a Terraform Cloud/Enterprise workspace (also queues a plan)
#!/usr/bin/env bash
readonly DEFAULT_VERSION='0.13.0'
readonly DEFAULT_API_HOST='app.terraform.io'
highlight() { echo -e "\033[36m$*\033[0m"; }
info() { echo -e "\033[36mINFO: $*\033[0m"; }
success() { echo -e "\033[32m$*\033[0m"; }
fail() { echo -e "\033[31mERROR: $*\033[0m" >&2; exit 1; }
@tomcant
tomcant / CompoundMap.ts
Created April 16, 2022 11:42
Use objects as TypeScript map keys with this CompoundMap class
export default class CompoundMap<K, V> implements Map<K, V> {
private readonly items: Map<string, { key: K; value: V }>;
constructor(entries: [K, V][] = []) {
this.items = new Map(
entries.map(([key, value]) => [this.toKey(key), { key, value }])
);
}
clear(): void {