Skip to content

Instantly share code, notes, and snippets.

View luketn's full-sized avatar

Luke Thompson luketn

View GitHub Profile
@luketn
luketn / token_revoked.py
Last active June 3, 2019 11:08
CloudFront Based Token Revocation System (only token_revoked may be called by CloudFront, responses will be cached)
from typing import Dict
import boto3
def lambda_handler(event: Dict, context):
try:
path: str = event['path']
if path.startswith('/api/token/revoked/'):
token_id: str = path.split('/')[4]
@luketn
luketn / http-timed-get.ts
Created June 14, 2019 05:11
Timed NodeJS HTTP Get
/**
* Broadly inspired by https://blog.risingstack.com/measuring-http-timings-node-js/
* And https://github.com/RisingStack/example-http-timings
*/
import {IncomingHttpHeaders} from "http";
const https = require('https');
const http = require('http');
const url_lib = require('url');
const NS_PER_SEC = 1e9;
{
"schemaVersion": "0.3",
"description": "AWSSupport-SetupIPMonitoringFromVPC creates an EC2 instance in the specified subnet and monitors selected target IPs by continuously running ping, MTR, traceroute and tracetcp tests. The results are stored in CloudWatch logs, and metric filters are applied to quickly visualize latency and packet loss statistics in a CloudWatch dashboard.",
"assumeRole": "{{ AutomationAssumeRole }}",
"parameters": {
"SubnetId": {
"type": "String",
"description": "(Required) The subnet ID for the monitor instance. NOTE: If you specify a private subnet, make sure there is Internet access to allow the monitor instance to setup the test (i.e. install the CloudWatch Logs agent, interact with AWS Systems Manager and Amazon CloudWatch).",
"allowedPattern": "^subnet-[a-z0-9]{8,17}$"
},
const child_process = require('child_process')
function run_script(command, args, realtimeCallback = (log, type) => {console.log(log)}) {
return new Promise((resolve) => {
let child = child_process.spawn(command, args)
let scriptOutput = ""
child.stdout.setEncoding('utf8')
child.stdout.on('data', function (data) {
@luketn
luketn / Docker.k6node
Created August 8, 2020 02:07
Docker file to install K6 and set up a NodeJS app to run.
FROM node:14.7.0
#Install K6
WORKDIR /tmp
ADD https://github.com/loadimpact/k6/releases/download/v0.27.1/k6-v0.27.1-linux64.tar.gz /tmp/k6-v0.27.1-linux64.tar.gz
RUN tar -xzf k6-v0.27.1-linux64.tar.gz
RUN mv k6-v0.27.1-linux64/k6 /usr/bin/k6
#Install NPM dependencies
COPY loadtest-home /loadtest-home
@luketn
luketn / docker-compose.yml
Created August 31, 2020 01:30
The docker-compose configuration file defines three servers and two networks, combining them together into a solution comprising a visualisation web server, database and load test client.
version: '3.4'
networks:
k6:
grafana:
services:
influxdb:
image: influxdb:latest
networks:
- k6
- grafana
apiVersion: 1
datasources:
- name: k6influxdb
type: influxdb
access: proxy
database: k6
url: http://influxdb:8086
isDefault: true
apiVersion: 1
providers:
- name: 'default'
org_id: 1
folder: ''
type: 'file'
options:
path: /var/lib/grafana/dashboards
import http from 'k6/http';
import { check } from "k6";
export let options = {
stages: [
// Ramp-up from 1 to 5 VUs in 5s
{ duration: "5s", target: 5 },
// Stay at rest on 5 VUs for 10s
{ duration: "10s", target: 5 },
// Ramp-down from 5 to 0 VUs for 5s
{ duration: "5s", target: 0 }
@luketn
luketn / TLSv1Test.java
Created November 9, 2020 01:42
This code makes an SSL/TLS connection to a domain and writes the results to a file. Used to check issues with older TLS / SNI protocols by passing flags to java to control these settings (see class comments).
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
/**