Skip to content

Instantly share code, notes, and snippets.

View andrew-templeton's full-sized avatar

Andrew Templeton andrew-templeton

View GitHub Profile
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);
};
}
All,
There have been questions about access to AWS resources, and how to gain tokens to make API requests. In order to reduce some of this friction, here is some context around how the system works.
Amazon Web Services uses a high-level identity management based on tokens, called IAM, or Identity and Access Management. There are several objects in this model: Groups, Policies, and Users. Each "User" is tied to a unique Access Key and Secret Key, analogous to a username and password on a Unix-like environment. These will henceforth be referenced as "Tokens" for sake of brevity. "Groups" are a logical grouping of users. One user may belong to many groups, and one group may have many users. "Policies" are pemission(s) granted to either Groups or Users. One policy may be granted to any number of these entities.
A "Policy" allows a Token pairing to make API calls. These policies, at a high level, consist of "Resources" and "Actions", which dictate who is allowed to do what on what resources. These are analog