Skip to content

Instantly share code, notes, and snippets.

@adamrneary
adamrneary / add-kinesis.diff
Last active August 29, 2015 14:11
Adding kinesis to our analytics endpoints
diff --git a/application.py b/application.py
index 15cb3eb..d4a21d7 100644
--- a/application.py
+++ b/application.py
@@ -11,6 +11,7 @@ from util import ThrottleQueue
from boto.dynamodb.table import Table
from boto.dynamodb.item import Item
from boto import connect_dynamodb
+from boto import connect_kinesis
@adamrneary
adamrneary / video-events-lamba-function.js
Created December 20, 2014 18:07
A simple function for Amazon Lambda
var Firebase = require('firebase');
var async = require('async');
// Extract data from the kinesis event
exports.handler = function(event, context) {
// This function abstracts the expected structure of any Kinesis payload,
// which is a base64-encoded string of a JSON object, passing the data to
// a private function.
function handlePayload(record, callback) {
@adamrneary
adamrneary / videoOdometer.coffee
Last active August 29, 2015 14:11
React/Firebase/Odometer prototype
React = require('react')
Firebase = require('firebase')
ReactFireMixin = require('reactfire')
OdometerComponent = require('react-odometer')
firebaseApp = 'https://luminous-heat-2841.firebaseio.com/'
projectId = location.hash.substring(1) or 324
ViewCount = React.createClass
mixins: [ReactFireMixin]
getInitialState: ->
@adamrneary
adamrneary / gulpfile.js
Last active April 14, 2018 13:28
Sample gulpfile for pushing functions to Lambda
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var rename = require('gulp-rename');
var install = require('gulp-install');
var zip = require('gulp-zip');
var AWS = require('aws-sdk');
var fs = require('fs');
var runSequence = require('run-sequence');
@adamrneary
adamrneary / package.json
Created December 23, 2014 03:13
NPM package.json for an AWS Lambda function
{
"name": "adventr-lambda-video",
"version": "0.0.0",
"description": "Initial lambda functions for Adventr",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Adam Neary <[email protected]> (http://adamrneary.com/)",
"license": "MIT",
@adamrneary
adamrneary / view-kinesis-events.js
Created December 23, 2014 03:40
A simple script to push Amazon Kinesis events to stdout
var dotenv = require('dotenv');
var kinesis = require('kinesis');
Transform = require('stream').Transform
dotenv.load();
// Data is retrieved as Record objects, so let's transform into Buffers
var bufferify = new Transform({objectMode: true})
bufferify._transform = function(record, encoding, cb) {
cb(null, record.Data)
@adamrneary
adamrneary / record-kinesis-events.js
Last active August 29, 2015 14:13
A simple node script for piping live Amazon Kinesis events to a flat file for analysis and replication
var kinesis = require('kinesis');
Transform = require('stream').Transform;
dotenv = require('dotenv');
es = require('event-stream');
fs = require('fs');
dotenv.load();
// Data is retrieved as Record objects, so we transform into Buffers.
var bufferify = new Transform({objectMode: true})
@adamrneary
adamrneary / kinesis-lambda-handler.js
Created January 8, 2015 16:31
Boilerplate handler function for processing Amazon Kinesis events with Amazon Lambda
// Extract data from the kinesis event
exports.handler = function(event, context) {
// This function abstracts the expected structure of any Kinesis payload,
// which is a base64-encoded string of a JSON object, passing the data to
// a private function.
function handlePayload(record, callback) {
encodedPayload = record.kinesis.data;
rawPayload = new Buffer(encodedPayload, 'base64').toString('utf-8');
handleData(JSON.parse(rawPayload), callback)
// This function mimics how our upstream code (in this case, the Flask beacon)
// pipes video events to Kinesis.
//
// campaignId - An Integer id for the campaign being viewed
// eventName - A String for the name of the event being recorded
//
// Returns a String containing the data as passed to Kinesis
function generateEvent(campaignId, eventName) {
var analyticsId = '123-' + campaignId + '-456';
var properties = {
describe('VideoEvents', function(){
var projectRef = getFirebaseRef();
var testId = getUniqueId();
describe('Video View', function(){
var eventName = 'Video View';
before(function(done) {
projectRef
.child(testId)