Skip to content

Instantly share code, notes, and snippets.

View jinman's full-sized avatar

Jinesh Varia jinman

View GitHub Profile
@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) {
//This is a sample lambda function that sends an Email or SMS on click of a button. It creates a SNS topic, subscribes an endpoint (SMS/EMAIL)
//to the topic and publishes to the topic.
/*
The following JSON template shows what is sent as the payload.
{
"serialNumber": "GXXXXXXXXXXXXXXXXX",
"batteryVoltage": "mV",
"clickType": "SINGLE | DOUBLE | LONG"
}
var AWS = require('aws-sdk');
var iotdata = new AWS.IotData({endpoint: '<CUSTOM ENDPOINT HERE>.iot.<REGION>.amazonaws.com'});
exports.handler = function(event, context) {
var params = {
thingName: '<THING NAME',
payload: '{"state":{"desired":{<STATE GOES HERE>}}}'
{
"sql": "SELECT (CASE Clicks WHEN '1' THEN 'Yo' WHEN '2' THEN 'Wassup?' ELSE 'Howdy.' END) AS message FROM 'button/press'",
"ruleDisabled": false,
"actions": [{
"sns": {
"roleArn": "arn:aws:iam::115330095819:role/icebreaker-sns-actions-role",
"targetArn": "arn:aws:sns:us-east-1:115330095819:text-a-phone"
}
}]
}
@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"
@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 / 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";