Skip to content

Instantly share code, notes, and snippets.

View astuyve's full-sized avatar

AJ Stuyvenberg astuyve

View GitHub Profile
@astuyve
astuyve / deny_snippet.json
Created January 17, 2024 15:00
Deny cloudwatch permissions from Lambda to save money
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
@astuyve
astuyve / lambda_streaming_out_of_order.js
Created June 22, 2023 16:27
Out of order response from Node.js response streaming - provided by Doug Moscrop and Ampt
const MAX_LINES = 30000
export const handler = awslambda.streamifyResponse(async (_event, responseStream, _context) => {
await new Promise((resolve, _reject) => {
let i = 1
responseStream.on('error', (err) => {
console.error('error:', err)
_reject(err)
})
responseStream.on('close', () => {
console.log('closed')
@astuyve
astuyve / eager_load_todo.js
Last active December 5, 2023 07:38
Eager loading todo list
'use strict';
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, PutCommand } = require("@aws-sdk/lib-dynamodb");
const dynamoClient = new DynamoDBClient({ region: process.env.AWS_REGION });
const ddbClient = DynamoDBDocumentClient.from(dynamoClient);
const { SNSClient, PublishBatchCommand } = require("@aws-sdk/client-sns");
const snsClient = new SNSClient({ region: process.env.AWS_REGION })
const { v4: uuidv4 } = require("uuid");
@astuyve
astuyve / lazy_load_todo.js
Created May 26, 2023 19:51
Lazy load todo app
'use strict';
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, PutCommand } = require("@aws-sdk/lib-dynamodb");
const dynamoClient = new DynamoDBClient({ region: process.env.AWS_REGION });
const ddbClient = DynamoDBDocumentClient.from(dynamoClient);
let snsClient, PublishBatchCommand, SNSClient
const { v4: uuidv4 } = require("uuid");
@astuyve
astuyve / index.mjs
Created May 3, 2023 02:29
AWS Lambda NodeJS 18 runtime extracted from image.
/** Copyright 2019,2020,2021,2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
// node_modules/lambda-runtime/dist/node16/index.mjs // AJ - I double checked, this was pulled from `public.ecr.aws/lambda/nodejs:18`, AWS did not change this comment ¯\_(ツ)_/¯
import { createRequire } from "module";
var require2 = createRequire(import.meta.url);
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
@astuyve
astuyve / custom_migrations.rb
Created June 26, 2018 19:33
Custom database migrations in Rails 5+
# Rails has long supported database migrations to help you evolve your database schema over time.
# However, mature Rails applications often need migration-like tasks which may not alter the schema, or may have special considerations.
# Specifically, I've had to implement an after-deploy migration pattern, and a late night migration pattern.
# After-deploys are used for non-schema changes. If I have a bunch of corrupt data to clean up, or a 1-time import to process,
# which doesn't really demand its own rake task.
# Late-night migrations might be schema changes that can lock a table or cause other issues that would arise during the day.
# Rails 5 introduced multi-database support, which also often benefits from multiple directories for migrations. You can leverage
# that logic and create a new task for special migrations like this
namespace :db do