Skip to content

Instantly share code, notes, and snippets.

View mikebroberts's full-sized avatar

Mike Roberts mikebroberts

View GitHub Profile
@mikebroberts
mikebroberts / template.yaml
Last active March 7, 2024 13:45
CloudFront Functions Demo with CloudFormation
Description: CloudFront Functions Demo
# This example shows how to use CloudFront, CloudFront Functions, and CloudFormation.
# In this simple example we setup CloudFront so that on any request we redirect to another site.
# While basic, this example can be expanded to provide typical redirect scenarios, based
# on the event passed to the function.
# This example written by Mike Roberts (https://twitter.com/mikebroberts), Symphonia.
# For more ideas about using AWS more effectively,see our blog at https://blog.symphonia.io/
@mikebroberts
mikebroberts / cdkApp.ts
Created April 28, 2022 20:35
Scheduled Step Function that calls a Lambda function, with backoff retry, in CDK
#!/usr/bin/env node
import 'source-map-support/register';
import {App, Duration, Stack, StackProps} from 'aws-cdk-lib';
import {Construct} from 'constructs';
import {Code, Function, Runtime} from "aws-cdk-lib/aws-lambda";
import {StateMachine} from "aws-cdk-lib/aws-stepfunctions";
import {LambdaInvoke} from "aws-cdk-lib/aws-stepfunctions-tasks";
import {Rule, RuleTargetInput, Schedule} from "aws-cdk-lib/aws-events";
import {SfnStateMachine} from "aws-cdk-lib/aws-events-targets";
@mikebroberts
mikebroberts / deleteAllItemsInTable.ts
Created October 11, 2024 17:47
Emptying / deleting all items in a DynamoDB table in TypeScript using the AWS Javascript SDK V3
import { BatchWriteCommand, DynamoDBDocumentClient, paginateScan } from '@aws-sdk/lib-dynamodb'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
function filterKeys<T extends object>(object: T, keyPredicate: (key: string) => boolean) {
return object ? Object.fromEntries(Object.entries(object).filter(([key]) => keyPredicate(key))) : object
}
function selectKeys<T extends object>(object: T, keys: string[]) {
return filterKeys(object, (key) => keys.includes(key))
}