Skip to content

Instantly share code, notes, and snippets.

@therightstuff
therightstuff / build-layers.js
Created August 30, 2023 22:46
Node/Python Lambda layer build script
"use strict"
// build-layers copies layers/src folder contents into layer/build, then runs
// the npm install and prune commands
const fs = require("fs");
const fse = require("fs-extra");
const path = require("path");
const spawn = require("child_process");
const { checksumDirectory } = require("simple-recursive-checksum");
// calculate md5 hash for entire src directory
// according to https://unix.stackexchange.com/a/35834/305967
console.log(`calculating md5 hash for ${layer}...`);
let hash = process.execSync(`tar -cf - ${layerSrcPath} | md5sum | cut -d ' ' -f 1`, { encoding: 'utf8' }).trim();
@therightstuff
therightstuff / requests_mocking.py
Last active May 31, 2023 08:34
Simple request mocking with requests_mock
def setup_mocker(mocker, expected_requests):
"""Note: this requires the exact number of expected requests.
expected_requests is an array in the following format:
[
{
"url": "https://www.example.com",
"method": "GET",
"exc": requests.exceptions.ConnectTimeout, # will override "status_code" and "json"
"status_code": 404, # defaults to 200
@therightstuff
therightstuff / README.md
Created April 28, 2023 09:25
AWS Breaking (Change) News: New S3 Buckets Blocked For Public Access

See the Medium article for more details.

In a nutshell: AWS has recently rolled out a change wherein S3 buckets cannot be created with public access.

These Serverless snippets are for use in the article, with the final.form.yaml being the one that worked for us, but mileage may vary and some people (and parts of our own solution) needed different options.

@therightstuff
therightstuff / is_between.sh
Last active January 23, 2023 06:11
A shell script to test whether the current time is between two given times
#!/usr/bin/env sh
# A script that receives start and end parameters in the format HH:mm and
# exit with an error code if the current time is not within the desired
# window.
# The given times are not inclusive, so if you want 06:00-10:00 inclusive
# you need to specify 05:59 and 10:01 respectively.
# This script assumes that we are interested in time periods shorter than
# a single day, and it handles overnight periods.
# Inspired by https://unix.stackexchange.com/a/395936/305967
@therightstuff
therightstuff / README.md
Last active March 5, 2023 22:15
Connecting a domain to a static-hosted S3 website with CDK 2
@therightstuff
therightstuff / lambda-simple-POST-form-data.js
Last active December 25, 2022 06:41
lambda handler for processing simple POST form data
exports.handler = async (event) => {
return new Promise(async (resolve) => {
const uriEncodedBody = event.body;
const uriEncodedBodyWithSpacesFixed = uriEncodedBody.replace(/\+/g, ' ');
const unencodedBody = decodeURIComponent(uriEncodedBodyWithSpacesFixed);
const arrayOfFormItems = unencodedBody.split('&');
console.log(arrayOfFormItems);
resolve({
"isBase64Encoded": false,
@therightstuff
therightstuff / parallel_test.sh
Last active July 28, 2023 00:29
Sample bash script for managing multiple parallel processes
#!/usr/bin/env bash
# inspired by https://stackoverflow.com/a/29535256/2860309
pids=""
failures=0
function my_process() {
seconds_to_sleep=$1
exit_code=$2
@therightstuff
therightstuff / .vscode-launch.json
Last active October 6, 2022 08:19
VSCode configuration for Python code coverage and debugging
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
@therightstuff
therightstuff / config.yml
Created October 2, 2022 15:13
How To Display The CircleCI Orb Versions In Use
version: 2.1
orbs:
my_orb: &my_orb_version my_namespace/my_orb@0.1.0
workflows:
my_workflow:
jobs:
- my_orb/audit:
# passes the fully qualified namespace/orb@version