Skip to content

Instantly share code, notes, and snippets.

View jinman's full-sized avatar

Jinesh Varia jinman

View GitHub Profile
@jinman
jinman / gist:2ac9e23ea748b2163cf7
Created September 29, 2015 01:58
LambdaToDynamoDB
console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context) {
console.log("Request received:\n", JSON.stringify(event));
console.log("Context received:\n", JSON.stringify(context));
var tableName = "CommonDynamoDBTable";
@jinman
jinman / LambdaToDynamoDBPut
Last active September 30, 2016 20:54
LambdaToDynamoDBPut
// create an IAM Lambda role with access to dynamodb
// Launch Lambda in the same region as your dynamodb region
// (here: us-east-1)
// dynamodb table with hash key = dsn
console.log('Loading function');
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context) {
// create an IAM Lambda role with access to dynamodb
// Launch Lambda in the same region as your dynamodb region
// (here: us-east-1)
// dynamodb table with hash key = dsn, uniqueid (hashkey for GSI), data (String/Blob)
console.log('Loading function');
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context) {
@jinman
jinman / gist:1dfae868bb18e950b0c031c80158e942
Created September 15, 2016 23:44
LambdaToNannyCheckinCheckout
/**
* This is a sample Lambda function that records nanny check in/out activities
* in DynamoDB and sends SMS messages to the phone number on file.
*
* This function creates a DynamoDB table 'button_nanny_checkin' the first time
* it runs. The table uses button's DSN as hash key and timestamp as range key.
* Each entry has an activity message.
*
* If phone number is set, an SMS message about this check in/out activity will
* be sent.
@jinman
jinman / LambdaToLIFXBulb
Created August 3, 2016 03:20
LambdaToLIFXBulb
var https = require('https');
/**
* Pass the data to send as `event.data`, and the request options as
* `event.options`. For more information see the HTTPS module documentation
* at https://nodejs.org/api/https.html.
*
* Will succeed with the response body.
*/
exports.handler = function(event, context) {
@jinman
jinman / gist:19e03a52e50fa6e939e4
Created September 29, 2015 01:45
LambdaToConsoleLog
exports.handler = function(event, context) {
var serialNumber = event.SerialNumber;
var clickType = event.ClickType;
console.log('Device with serial number', serialNumber, "was", clickType.toLowerCase(), "pressed.");
};
@jinman
jinman / gist:d9854e0bb3e071331a48
Created September 29, 2015 01:48
LambdaToSNS
var aws = require('aws-sdk');
var sns = new aws.SNS();
exports.handler = function(event, context) {
payload1 = new Buffer(event.payload);
console.log(payload1);
var payload2 = payload1 + ' -- processed by Lambda';
console.log(payload2);
var params = {
Message: payload2,
@jinman
jinman / gist:2fc74aa15ac2cedb2dd3
Created September 29, 2015 01:52
LambdaToTwilio
console.log('Loading event');
// Twilio Credentials
var accountSid = '<your twilio Sid>';
var authToken = '<your twilio authtoken>';
var fromNumber = '<your from number>';
var toNumber = '<your to number>'
var https = require('https');
var queryString = require('querystring');
@jinman
jinman / gist:21503b694b99d96fc04c
Created September 29, 2015 01:56
LambdaToLambda
console.log('Loading event');
var AWS = require('aws-sdk');
exports.handler = function(event, context) {
console.log("Request received:\n", JSON.stringify(event));
console.log("Context received:\n", JSON.stringify(context));
var lambdaFunctionArn = "arn:aws:lambda:us-west-2:555818481905:function:ProcessDeviceData-iot-test-hack-event-1";
var lambdaRegion = "us-west-2";
@jinman
jinman / gist:75367fc8466753ccbe45
Last active August 2, 2016 19:15
LambdaToIoTHTTP
var aws = require('aws-sdk');
var iot = = new AWS.Iot();
var iotData = = new AWS.IotData();
exports.handler = function(event, context) {
// Exercising an IoT Data operation as an example
var params = {
"topic" : "foo/bar",
"payload" : "hello world"