Skip to content

Instantly share code, notes, and snippets.

View thomasmichaelwallace's full-sized avatar
🐧

thomas michael wallace thomasmichaelwallace

🐧
View GitHub Profile
@thomasmichaelwallace
thomasmichaelwallace / taskdef-to-env.ts
Created May 8, 2024 10:36
Convert an ECS task definition into a dot env file
import {
GetSecretValueCommand,
SecretsManagerClient,
} from '@aws-sdk/client-secrets-manager';
import fs from 'fs';
import path from 'path';
// usage npx tsx taskdef-to-env.ts path/to/ecs/task-definition.json
// outputs: /path/to/ecs/.env.local
// expects aws to be configured (see aws-vault)
@thomasmichaelwallace
thomasmichaelwallace / README.md
Last active October 5, 2021 11:56
serverless framework credential_process patch

About

This gist provides a patch-package patch that tracks the serverless framework and provides a fix for #4838 (support for credential_process).

We use AWS SSO at devicepilot, and credentials_process provides a convenient way to polyfill the aws-sdk (and serverless framework) with support for it (see: https://github.com/benkehoe/aws-sso-credential-process).

There's still some work to be done refactoring the serverless framework before a PR for this patch can be accepted. However, as I've already committed to using and maintaining this patch in production, I thought I would make it publicly available for the impatient.

Until it is accepted as a PR, I'll maintain this patch against a relatively recent

@thomasmichaelwallace
thomasmichaelwallace / backfill-releases.js
Created April 15, 2020 12:53
Use lerna to backfill GitHub release notes from a change log.
/* eslint-disable no-console */
const createRelease = require('@lerna/version/lib/create-release.js'); // eslint-disable-line import/no-extraneous-dependencies
const fs = require('fs');
function parseEntry(entry) {
const lines = entry.split('\n');
const header = lines.shift();
const [version] = header.split(']');
const tag = `v${version}`;
const title = `# [${header}`;
@thomasmichaelwallace
thomasmichaelwallace / config.js
Created April 30, 2019 16:40
squirreldex: config
const AWS = require('aws-sdk');
const lambda = new AWS.lambda();
async function updateSotd(sotd) {
// pick one of the 1000 squirrels at random:
const id = Math.floor(Math.random() * 1000);
// build an environment with the new SD_SOTD value:
const Variables = { SD_SOTD: sotd };
const params = {
@thomasmichaelwallace
thomasmichaelwallace / db.js
Created April 30, 2019 16:37
squirreldex: the database module
// in node, a json file is just a module that exports a javascript object
// in this case, data.json is a map of squirrels keyed by id.
const data = require('./data.json');
const AdmZip = require('adm-zip') // node does not have native zip support
const AWS = require('aws-sdk');
const lambda = new AWS.lambda();
@thomasmichaelwallace
thomasmichaelwallace / handler.js
Last active April 30, 2019 16:24
squirreldex: lambda handler
exports.handler = async function (event, context) {
// parse the event, get the squirrel, save the world.
// (this is javascript, read from the bottom to the top!)
const { action } = event || {};
if (action === 'update-squirrel') {
// route c: invoked by an admin looking to update an entry on a squirrel.
const { id, entry } = event;
await db.update(id, entry);
return { status: 'super effective' };
@thomasmichaelwallace
thomasmichaelwallace / data.json
Created April 30, 2019 08:02
Made up test data.
[
{ "id": "device-one", "temperature": { "min": 5, "max": 30 }, "label": "14 Air Street" },
{ "id": "device-two", "temperature": { "min": 1, "max": 29 }, "label": "25 Rose Road" },
{ "id": "device-three", "temperature": { "min": 4, "max": 31 }, "label": "14 Brick Street" },
{ "id": "device-four", "temperature": { "min": -1, "max": 15 }, "label": "17 Mull Street" },
{ "id": "device-five", "temperature": { "min": 0, "max": 20 }, "label": "15 Raid Drive" },
{ "id": "device-six", "temperature": { "min": 10, "max": 22 }, "label": "26 Air Street" },
{ "id": "device-seven", "temperature": { "min": 4, "max": 33 }, "label": "34 Box Road" },
{ "id": "device-eight", "temperature": { "min": 0, "max": 29 }, "label": "114 Rosebery Street" },
{ "id": "device-nine", "temperature": { "min": 8, "max": 25 }, "label": "182 Basil Street" },
@thomasmichaelwallace
thomasmichaelwallace / aws-sdk-bm-v3.js
Created March 27, 2019 20:49
aws-sdk benchmark: v3
import { DynamoDB } from '@aws-sdk/client-dynamodb-v2-node';
const ddb = new DynamoDB.DocumentClient({ region: 'eu-west-1' });
export async function handleV2(event) { // eslint-disable-line import/prefer-default-export
const { TableName, Key } = event;
const { Item } = await ddb.get({ TableName, Key });
return Item || {};
}
@thomasmichaelwallace
thomasmichaelwallace / aws-sdk-bm-direct.js
Created March 27, 2019 20:45
aws-sdk benchmark: direct
import DynamoDB from 'aws-sdk/clients/dynamodb';
const ddb = new DynamoDB.DocumentClient({ region: 'eu-west-1' });
export async function handleV2(event) { // eslint-disable-line import/prefer-default-export
const { TableName, Key } = event;
const { Item } = await ddb.get({ TableName, Key }).promise();
return Item || {};
}
@thomasmichaelwallace
thomasmichaelwallace / aws-sdk-bm-import.js
Created March 27, 2019 20:41
aws-sdk benchmark: import
import { DynamoDB } from 'aws-sdk';
const ddb = new DynamoDB.DocumentClient({ region: 'eu-west-1' });
export async function handleV2(event) { // eslint-disable-line import/prefer-default-export
const { TableName, Key } = event;
const { Item } = await ddb.get({ TableName, Key }).promise();
return Item || {};
}