Skip to content

Instantly share code, notes, and snippets.

Avatar

John McKim johncmckim

View GitHub Profile
@johncmckim
johncmckim / package.json
Last active May 1, 2017
Prune Lambda Functions - PLEASE REVIEW AND USE AT YOUR OWN RISK
View package.json
{
"dependencies": {
"aws-sdk": "^2.7.10",
"bluebird": "^3.4.6",
"lodash": "^4.17.2",
"moment": "^2.17.1"
}
}
@johncmckim
johncmckim / faceswap.js
Last active Jan 15, 2017
Emoticon Faceswap Handler
View faceswap.js
'use strict';
const BbPromise = require('bluebird');
const path = require('path');
const logger = require('./logger');
const processor = require('./processor');
const rekognition = require('./rekognition');
const BUCKET_NAME = process.env.BUCKET_NAME;
@johncmckim
johncmckim / serverless.yml
Created Jan 15, 2017
Emoticon Faceswap serverless.yml
View serverless.yml
service: serverless-emoticon-faceswap
provider:
name: aws
runtime: nodejs4.3
# Allow Lambda to access Rekognition and S3
iamRoleStatements:
- Effect: Allow
Action:
- rekognition:DetectFaces
Resource: '*'
View keybase.md

Keybase proof

I hereby claim:

  • I am johncmckim on github.
  • I am johncmckim (https://keybase.io/johncmckim) on keybase.
  • I have a public key ASA3Auj6jyN4fFD4UjSQ2XJMWdfYLDiptLs-FWB23bkK6wo

To claim this, I am signing this object:

@johncmckim
johncmckim / garden-aid-iot-device.js
Created Sep 19, 2016
Garden Aid - IoT Hub - Device
View garden-aid-iot-device.js
const awsIot = require('aws-iot-device-sdk');
const interval = 1000 * 60 * 1; // one minute
const device = awsIot.device({
keyPath: './path/to/your/private.pem.key',
certPath: './path/to/your/certificate.pem.crt',
caPath: './path/to/your/verisign-ca.pem',
clientId: 'garden-aid-client-test-js',
region: 'ap-southeast-2'
@johncmckim
johncmckim / garden-aid-iot-hub-serverless.yml
Last active Nov 24, 2017
Garden Aid - IoT Hub - serverless.yml
View garden-aid-iot-hub-serverless.yml
service: garden-aid-iot-hub
provider:
name: aws
runtime: nodejs4.3
# custom variable syntax is needed to avoid conflits with aws cloudformation functions
variableSyntax: '\${{([\s\S]+?)}}'
# load custom variables from a file
custom: ${{file(./vars-${{opt:stage}}.yml)}}
@johncmckim
johncmckim / garden-aid-iot-hub-serverless-iot.yml
Last active Nov 29, 2020
Garden Aid - IoT Hub - IoT Resources
View garden-aid-iot-hub-serverless-iot.yml
SensorThing:
Type: AWS::IoT::Thing
Properties:
AttributePayload:
Attributes:
SensorType: soil
SensorThingPolicy:
Type: AWS::IoT::Policy
Properties:
@johncmckim
johncmckim / garden-aid-iot-hub-serverless-dynamodb.yml
Last active Jun 2, 2017
Garden Aid - IoT Hub - DynamoDB Table
View garden-aid-iot-hub-serverless-dynamodb.yml
MoistureData:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: moisture-data-${{opt:stage}}
AttributeDefinitions:
-
AttributeName: ClientId
AttributeType: S
-
@johncmckim
johncmckim / garden-aid-slack-webhook.js
Created Sep 4, 2016
Garden Aid - Chat - Slack Webhook
View garden-aid-slack-webhook.js
const BbPromise = require('bluebird');
const rp = require('request-promise');
module.exports.notify = (event, context, cb) => {
const promises = [];
event.Records.forEach(function(record) {
if(record.EventSource !== 'aws:sns') {
console.warn('Recieved non sns event: ', record);
@johncmckim
johncmckim / garden-aid-moisture-check.js
Created Sep 4, 2016
Garden Aid - IoT - Moisture Check
View garden-aid-moisture-check.js
const AWS = require('aws-sdk');
const sns = new AWS.SNS();
// Example event
// { DeviceId: 'test-js-device', Recorded: '2016-08-14T12:39:06.765Z', Level: 3.59334681998007 }
module.exports.checkLevel = (event, context, cb) => {
if(event.Level >= 2.5) {
cb(null, { message: 'No message to publish', event: event });
You can’t perform that action at this time.