Skip to content

Instantly share code, notes, and snippets.

View andrew-templeton's full-sized avatar

Andrew Templeton andrew-templeton

View GitHub Profile
@andrew-templeton
andrew-templeton / aws-readonly
Last active February 4, 2026 20:08
AWS SSO to read-only session for agent use
#!/bin/bash
# aws-readonly
# Creates a 12-hour read-only AWS session for agent use
# Auto-creates the ReadOnlyAccess role via CloudFormation if it doesn't exist
#
# Usage: aws-readonly <sso-profile-name> [output-profile-name]
#
# Example:
# aws-readonly csc-prod-admin # Creates csc-prod-admin-readonly
# aws-readonly csc-prod-admin agent-ro # Creates agent-ro
chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken chicken
chicken chicken chicken chicken chicken chicken
chicken
@andrew-templeton
andrew-templeton / rule.json
Last active June 24, 2016 18:57
Generic lambda cron CloudFormation substack
{
"Parameters": {
"TARGET_LAMBDA_ARN": {
"Type": "String"
},
"EXEC_SCHEDULE": {
"Type": "String"
},
"RULE_NAME": {
"Type": "String"
@andrew-templeton
andrew-templeton / index.js
Last active June 6, 2016 18:52
Embedded Lambda custom resource for getting an EB Environment's ELB's CanonicalHostedZoneId
var AWS = require('aws-sdk');
var response = require('cfn-response');
exports.handler = function(event, context) {
console.log('REQUEST RECEIVED: %j', event);
if (event.RequestType == 'Delete') {
response.send(event, context, response.SUCCESS);
return;
@andrew-templeton
andrew-templeton / index.js
Created April 1, 2016 03:12
lambda function to test the IP of your lambda as seen by ifconfig.co
var http = require('http');
exports.handler = function (event, context) {
http.get('http://ifconfig.co', function (res) {
var buff = [];
console.log('Got response: %s', res.statusCode);
res.on('data', function (chunk) {
buff.push(chunk);
});
res.on('end', function () {
console.log('Found: %s', buff.join(''));
@andrew-templeton
andrew-templeton / vpc.json
Created April 1, 2016 02:20
CloudFormation template packaging a serverless VPC for fixed/static IPs on Lambdas
{
"Description": "Host VPC for Lambda Static IPs",
"Parameters": {
"VPCClassBOctet": {
"Type": "Number",
"Description": "The Class B block to use for the VPC (0-255).",
"MaxValue": 255,
"MinValue": 0,
"Default": 0
},
@andrew-templeton
andrew-templeton / aws-cloudwatch-events-rule-scheduleexpression.js
Created February 28, 2016 07:59
Full Regex for ScheduleExpression property of AWS CloudWatch Events Rule
"^(rate\\(((1 (hour|minute|day))|(\\d+ (hours|minutes|days)))\\))|(cron\\(\\s*($|#|\\w+\\s*=|(\\?|\\*|(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?(?:,(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?)*)\\s+(\\?|\\*|(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?(?:,(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?)*)\\s+(\\?|\\*|(?:[01]?\\d|2[0-3])(?:(?:-|\/|\\,)(?:[01]?\\d|2[0-3]))?(?:,(?:[01]?\\d|2[0-3])(?:(?:-|\/|\\,)(?:[01]?\\d|2[0-3]))?)*)\\s+(\\?|\\*|(?:0?[1-9]|[12]\\d|3[01])(?:(?:-|\/|\\,)(?:0?[1-9]|[12]\\d|3[01]))?(?:,(?:0?[1-9]|[12]\\d|3[01])(?:(?:-|\/|\\,)(?:0?[1-9]|[12]\\d|3[01]))?)*)\\s+(\\?|\\*|(?:[1-9]|1[012])(?:(?:-|\/|\\,)(?:[1-9]|1[012]))?(?:L|W)?(?:,(?:[1-9]|1[012])(?:(?:-|\/|\\,)(?:[1-9]|1[012]))?(?:L|W)?)*|\\?|\\*|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?(?:,(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?)*)\\s+(\\?|\\*|(?:[0-6])(?:(?:-|\/|\\,|#)(?:[0-6]))?(?:L)?(?:,(?:[0-
@andrew-templeton
andrew-templeton / cron-regex.js
Created February 28, 2016 06:05
Regex to validate cron expressions
"^\\s*($|#|\\w+\\s*=|(\\?|\\*|(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?(?:,(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?)*)\\s+(\\?|\\*|(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?(?:,(?:[0-5]?\\d)(?:(?:-|\/|\\,)(?:[0-5]?\\d))?)*)\\s+(\\?|\\*|(?:[01]?\\d|2[0-3])(?:(?:-|\/|\\,)(?:[01]?\\d|2[0-3]))?(?:,(?:[01]?\\d|2[0-3])(?:(?:-|\/|\\,)(?:[01]?\\d|2[0-3]))?)*)\\s+(\\?|\\*|(?:0?[1-9]|[12]\\d|3[01])(?:(?:-|\/|\\,)(?:0?[1-9]|[12]\\d|3[01]))?(?:,(?:0?[1-9]|[12]\\d|3[01])(?:(?:-|\/|\\,)(?:0?[1-9]|[12]\\d|3[01]))?)*)\\s+(\\?|\\*|(?:[1-9]|1[012])(?:(?:-|\/|\\,)(?:[1-9]|1[012]))?(?:L|W)?(?:,(?:[1-9]|1[012])(?:(?:-|\/|\\,)(?:[1-9]|1[012]))?(?:L|W)?)*|\\?|\\*|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?(?:,(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?)*)\\s+(\\?|\\*|(?:[0-6])(?:(?:-|\/|\\,|#)(?:[0-6]))?(?:L)?(?:,(?:[0-6])(?:(?:-|\/|\\,|#)(?:[0-6]))?(?:L)?)*|\\?|\\*|(?:MON|TUE|WED|THU|FRI|S
@andrew-templeton
andrew-templeton / example-ddb-scaler.json
Created November 21, 2015 21:44
Proposed CloudFormation custom resource interface for DynamoDB AutoScaler Resource
"MyDynamoAutoScaler": {
"Type": "Custom::DynamoDBAutoScaling",
"Properties": {
"TableName": {"Ref": "MyDynamoTable"},
"CheckInterval": 300,
"ScaleReadsUpAbove": 90,
"IncreaseReadsBy": 50,
"ScaleReadsDownBelow": 30,
function add(x, y) {
return x + y;
}
function toThe(pow) {
return function(base) {
return Math.pow(base, pow);
};
}