Skip to content

Instantly share code, notes, and snippets.

View mandrews's full-sized avatar
🎯
Focusing

Michael Andrews mandrews

🎯
Focusing
View GitHub Profile
@mandrews
mandrews / test.sh
Created October 29, 2018 20:40
Running AWS SAM in a Docker Container: test.sh
echo '{"itemRecord":{"value":[{"longValue":"12345"},{"stringValue":{"number":"false","$t":"this is a string value"}},{"moneyValue":{"number":"true","currencyId":"USD","text":"123.45","$t":"104.95"}},{"moneyValue":{"currencyId":"USD","$t":"104.95"}},{"longValue":"0","bool":{"id":"0","$t":"true"}},{"longValue":"0"},{"dateValue":"2012-02-16T17:03:33.000-07:00"},{"stringValue":"SmDZ8RlMIjDvlEW3KUibzj2Q"},{"text":"42.42"}]}}' | curl \
--request POST \
--header "Content-Type: application/json" \
--data @- \
http://localhost:3001/2015-03-31/functions/SampleFunction/invocations
@mandrews
mandrews / template.yaml
Created October 29, 2018 20:39
Running AWS SAM in a Docker Container: template.yaml
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A sample AWS Lambda Function
Resources:
SampleFunction:
Type: AWS::Serverless::Function
Properties:
Handler: dist/index.handler
Runtime: nodejs8.10
CodeUri: ./
@mandrews
mandrews / docker-compose.yaml
Created October 29, 2018 20:38
Running AWS SAM in a Docker Container: docker-compose.yaml (2)
version: '3.6'
services:
sam_app:
build: .
command: ["$PWD"]
ports:
- "3001:3001"
volumes:
- .:/app
- /var/run/docker.sock:/var/run/docker.sock
@mandrews
mandrews / sam_entrypoint.sh
Created October 29, 2018 20:37
Running AWS SAM in a Docker Container: sam_entrypoint.sh
#!/bin/bash
set -o errexit
BASEDIR="$1"
/usr/local/bin/sam local start-lambda \
--template dist/template.yaml \
--host 0.0.0.0 \
--docker-volume-basedir "${BASEDIR}" \
--docker-network monsoon-samples_default \
--skip-pull-image
@mandrews
mandrews / Dockerfile
Created October 29, 2018 20:36
Running AWS SAM in a Docker Container: Dockerfile
FROM python:alpine
RUN apk update && \
apk upgrade && \
apk add bash && \
apk add --no-cache --virtual build-deps build-base gcc && \
pip install aws-sam-cli && \
apk del build-deps
RUN mkdir /app
WORKDIR /app
EXPOSE 3001
@mandrews
mandrews / docker-compose.yaml
Last active October 29, 2018 20:33
Running AWS SAM in a Docker Container: docker-compose.yaml(1)
version: '3.6'
services:
lambda_npm_app:
image: lambci/lambda:build-nodejs8.10
volumes:
- .:/var/task
@mandrews
mandrews / package.json
Last active October 30, 2018 00:22
Running AWS SAM in a Docker Container: package.json
{
"private": true,
"description": "Dockerized SAM",
"main": "index.js",
"scripts": {
"tsc": "tsc"
},
"dependencies": {
"xml2json": "^0.11.2"
},
@mandrews
mandrews / index.ts
Last active October 30, 2018 00:21
Running AWS SAM in a Docker Container: index.ts
import * as xml2json from 'xml2json';
import { Callback, Context, Handler } from 'aws-lambda';
const handler: Handler = (event: any, context: Context, callback: Callback): void => {
console.log("received event: %j", event);
const xml = xml2json.toXml(event);
callback(null, xml);
};
export { handler }
@mandrews
mandrews / 00_example.sql
Last active September 11, 2019 00:35
Example of deriving latest listing from price history. Also a technique for preserving last N pricing events and constant time pruning
DROP TABLE price_history_events CASCADE;
CREATE TABLE price_history_events (
id SERIAL PRIMARY KEY,
tenant_id INTEGER,
product_id INTEGER,
price MONEY,
created_date DATE DEFAULT NOW(),
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE OR REPLACE FUNCTION hstore_merge(left HSTORE, right HSTORE) RETURNS HSTORE AS $$
SELECT $1 || $2;
$$ LANGUAGE SQL;
CREATE AGGREGATE hstore_merge (HSTORE) (
SFUNC = hstore_merge,
STYPE = HSTORE,
INITCOND = ''
);