Skip to content

Instantly share code, notes, and snippets.

Eric Johnson singledigit

Block or report user

Report or block singledigit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@singledigit
singledigit / handler.js
Created Oct 15, 2019
Lambda API Gateway Response Handler
View handler.js
const isLocal = process.env.AWS_SAM_LOCAL;
const handlerModel = (body, headers, code) => {
let response = {
'statusCode': code,
'body': JSON.stringify(body)
}
if(headers.length > 0) {
response.headers = response.headers || {};
@singledigit
singledigit / EventBridgeRule.yaml
Created Sep 25, 2019
Using EventBridge rules as events in AWS SAM
View EventBridgeRule.yaml
TranslateFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: translate/
Timeout: 10
Handler: app.lambdaHandler
Runtime: nodejs10.x
Events:
TranslateEvent:
Type: CloudWatchEvent
@singledigit
singledigit / SAM-Lambda-Layer.yaml
Last active Oct 21, 2019
How to create and manage a Lambda Layer using AWS SAM
View SAM-Lambda-Layer.yaml
## Manage your Lambda layer in SAM
## This creates a layer and the permissions for the layer. This particular permission opens it to the world.
## I then use 'sam package' and 'sam deploy' to create/update the layer
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Lambda Layer
Resources:
MyLayer:
@singledigit
singledigit / vue.config.js
Created Jul 8, 2019
Enable preview and live reloading on Cloud9 with Vue-CLI apps
View vue.config.js
module.exports = {
devServer: {
disableHostCheck: true,
public: 'https://[your cloud9 host id].vfs.cloud9.[region].amazonaws.com'
}
}
View node8hello.js
const http = require('http');
const hostname = '0.0.0.0';
const port = process.env.PORT || 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
@singledigit
singledigit / infrastructure.yaml
Last active Aug 17, 2018
Secure S3 hosting bucket with CloudFront distro. Only allows distro access to the bucket
View infrastructure.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: AWS S3 Hosting bucket and CloudFront Distrobution
Resources:
## Origin Access ID for CloudFront
HostAccessIdentity:
Type: "AWS::CloudFront::CloudFrontOriginAccessIdentity"
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: MyHostBucketId
@singledigit
singledigit / handler.js
Last active Jun 22, 2018
RDS Snapshot Lambda for automating manual backups.
View handler.js
const AWS = require('aws-sdk');
const rds = new AWS.RDS();
const sns = new AWS.SNS();
const prefix = `snapper-${process.env.TIME_TO_LIVE}-${process.env.TIME_TO_LIVE_METRIC}-${process.env.CLUSTER_ID}`
const createClusterSnapshot = () => {
let params = {
DBClusterIdentifier: process.env.CLUSTER_ID,
DBClusterSnapshotIdentifier: `${prefix}-${Date.now()}`,
Tags: [{ Key: 'type', Value: 'snapper' }]
@singledigit
singledigit / cognito.yaml
Last active Nov 28, 2019
Create a Cognito Authentication Backend via CloudFormation
View cognito.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: Cognito Stack
Parameters:
AuthName:
Type: String
Description: Unique Auth Name for Cognito Resources
Resources:
# Creates a role that allows Cognito to send SNS messages
SNSRole:
@singledigit
singledigit / Usage
Last active Mar 27, 2017
Aurelia value-converter allowing two string values to be used as a checkbox boolean
View Usage
<input type="checkbox" checked.bind="color | checkedValue:'Green':'Blue'" />
@singledigit
singledigit / Base File
Last active Jun 7, 2018
Cloudformation Files for Creating a Serverless CICD Pipeline
View Base File
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Deployment Stack'
Parameters:
GitHubToken:
NoEcho: true
Type: String
Description: Secret. It might look something like 9b189a1654643522561f7b3ebd44a1531a4287af OAuthToken with access to Repo. Go to https://github.com/settings/tokens"
GitHubOwner:
Type: String
Description: GitHub UserName
You can’t perform that action at this time.