Skip to content

Instantly share code, notes, and snippets.

@a-h
a-h / run.sh
Created March 14, 2018 08:32
Invoke out-of-memory Lambda
aws lambda invoke \
--invocation-type RequestResponse \
--function-name oom-dev-memory \
--region eu-west-2 \
--log-type Tail \
--payload "{}" \
output.txt
@a-h
a-h / ecs_launch_configuration.tf
Created December 15, 2017 14:27
ECS security group
resource "aws_launch_configuration" "ecs_cluster" {
name = "${var.environment}-${var.application}-ecs"
image_id = "${lookup(var.ecs_amis, var.region)}"
instance_type = "${var.ecs_instance_type}"
key_name = "${var.key_name}"
iam_instance_profile = "${aws_iam_instance_profile.ecs_cluster.name}"
security_groups = ["${aws_security_group.ecs-cluster-group.id}", "${aws_security_group.ecs-api.id}"]
user_data = "#!/bin/bash\necho ECS_CLUSTER=${aws_ecs_cluster.ecs_cluster.name} >> /etc/ecs/ecs.config"
lifecycle {
@a-h
a-h / ecs-task.json
Created December 15, 2017 14:12
ECS task with specified ports
[
{
"name": "${name}",
"image": "12327816371.dkr.ecr.eu-west-2.amazonaws.com/repository:${tag}",
"cpu": 128,
"memory": 128,
"entryPoint": [],
"environment": [
{
"name": "CONNECTION_STRING",
@a-h
a-h / claims.json
Created December 13, 2017 13:53
Cognito Claims
{
"sub": "<uuid_user_id>",
"aud": "...",
"email_verified": true,
"event_id": "<uuid>",
"token_use": "id",
"auth_time": 1513169066,
"iss": "https://cognito-idp.eu-west-2.amazonaws.com/eu-west-2_pool_id",
"cognito:username": "<uuid_user_id>",
"exp": 1513172666,
@a-h
a-h / backend.txt
Created December 13, 2017 13:47
Backend request
GET / HTTP/1.1
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI8dXVpZF91c2VyX2lkPiIsImF1ZCI6Ii4uLiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJldmVudF9pZCI6Ijx1dWlkPiIsInRva2VuX3VzZSI6ImlkIiwiYXV0aF90aW1lIjoxNTEzMTY5MDY2LCJpc3MiOiJodHRwczovL2NvZ25pdG8taWRwLmV1LXdlc3QtMi5hbWF6b25hd3MuY29tL2V1LXdlc3QtMl9wb29sX2lkIiwiY29nbml0bzp1c2VybmFtZSI6Ijx1dWlkX3VzZXJfaWQ-IiwiZXhwIjoxNTEzMTcyNjY2LCJpYXQiOjE1MTMxNjkwNjYsImVtYWlsIjoiPGVtYWlsPiJ9.9ywdi62LvgoRntmqERoynjCm9ygKqLPwQSBlWsI7ZjE
x-amzn-apigateway-api-id: id
Accept: application/json
User-Agent: AmazonAPIGateway_name
X-Amzn-Trace-Id: Root=1-5a312506-a72c08ef3a10edd4481c0441
Host: 6804bc51.ngrok.io
X-Forwarded-For: ipv4
@a-h
a-h / curl
Created December 13, 2017 13:35
Use Authorization header
curl -H "Authorization: <cognito_idtoken>" https://xxxxxxx.execute-api.eu-west-2.amazonaws.com/dev
@a-h
a-h / 401.json
Created December 13, 2017 13:32
API Gateway Unauthorized Response
{"message":"Unauthorized"}
@a-h
a-h / index.js
Last active May 17, 2022 05:27
JSON logging in winston with a timestamp
const winston = require('winston');
const MESSAGE = Symbol.for('message');
const jsonFormatter = (logEntry) => {
const base = { timestamp: new Date() };
const json = Object.assign(base, logEntry)
logEntry[MESSAGE] = JSON.stringify(json);
return logEntry;
}
@a-h
a-h / main.go
Last active November 26, 2017 14:52
Date parsing
package main
import (
"fmt"
"reflect"
"time"
"github.com/a-h/lexical/input"
"github.com/a-h/lexical/parse"
)
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
"reflect"