By Fritzi Borja

Amazon Web Services (AWS) is changing the way engineers develop solutions. It is so easy to prototype and have a scalable architecture with very little hand holding from the Office of the CTO or Systems Engineers. This, in turn, fosters the DevOps culture within the organization.

One of the prototypes we’ve tried is to integrate AWS with Twilio, Slack and Intel Edison + Grove IoT device. We cannot take all the credit here because this was inspired by a recent trip to AWS’s San Francisco pop-up loft. They had a zombie apocalypse themed workshop but we took it a step further and used our company use cases and dissected each step since when we were there, we were just going through the motions. We also thought that learning about how some of these technology companies work will provide us a fresh new perspective on what is moving and shaking the software industry.

The discussion below assumes some AWS knowledge of some of the services used. It does not elaborate on each service and explain it in detail but here’s a quick refresher taken from AWS themselves:

Lambda — “Lets you run code without provisioning or managing servers. You pay only for the compute time you consume — there is no charge when your code is not running” API Gateway — “Makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale” SNS — “Pub-sub Service for Mobile and Enterprise Messaging” Dynamo DB — “Fast and flexible NoSQL database service”

Let’s get right to it, shall we? First up…

Twilio

Twilio is a technology company that allows programmable communications. They are the interface for sending and receiving global SMS and MMS messaging from any app.

Who uses Twilio?

Box Nordstrom OpenTable Intuit Uber EMC2 Zendesk Cocacola

Main competitors:

Nexmo Plivo

Use Case:

Our use case is to send a client their next scheduled appointment to speak with one of our investment advisors if they send a text message of “schedule”. For this prototype, the date would have been previously set.

Solution Architecture

Components:

User-appt-schedule is the API gateway that fronts the lambda function named user-schedule-get. The lambda function then fetches the data from the dynamo DB for the schedule date.

AWS:

Create your Dynamo DB with the primary key of phone number and column for appointment date.

Create your node JS lambda function with that gets the date from the DB given the phone number.

console.log('Loading function');

var aws = require('aws-sdk');

var ddb = new aws.DynamoDB({

region: "us-west-2",

params: {

TableName: "participant-schedule-reminder"

}

}); var theContext; function dynamoCallback(err, response) {

if (err) {

console.log('error' + err, err.stack); // an error occurred

theContext.fail(err);

} else {

console.log('result: ' + JSON.stringify(response)) // success

console.log('parsed response ' + JSON.stringify(response.Item.scheduledDate.S).replace("\"", ""));

theContext.succeed("Your next retirement checkup is scheduled on " +

JSON.stringify(response.Item.scheduledDate.S).replace("\"", ""));

}

} exports.handler = function(event, context, callback) {

theContext = context;

console.log("Request received:

", JSON.stringify(event));

console.log("Context received:

", JSON.stringify(context)); // Determine text

var textBody = event.body; // Get the phone number, only the last 10 characters

var phoneNumber = event.fromNumber.substring(2, 12);

console.log('phone ' + phoneNumber); if (event.body.trim() == "schedule") { var params = {

Key: {

"phone-number": { N: phoneNumber }

},

AttributesToGet: [

"scheduledDate"

],

} var response = ddb.getItem(params,dynamoCallback);

} else {

theContext.succeed("Text 'schedule' to get your retirement check up date");

}

};

3. Create your API gateway that invokes the lambda function for each get request. The nuance with this is that every request that comes from Twilio is in TwiML format (XML format) but our lambda function requires a JSON object so a conversion has to be done in the integration piece of the API gateway and every JSON response from the lambda function needs to be converted to TwiML format.

Twilio:

You can sign up for a trial account with Twilio and they you will get a phone number from them. You can then program this phone number with web hooks. The URL below is the ARN URL from AWS for the API gateway.

Slack

Slack is an instant messaging and collaboration system. They have teams and channels and have robust features for search. There are commands that can be programmed called “slash commands” which allows for forwarding the message typed in the chat box to an external source with the use of a web hook.

Who uses Slack?

Airbnb CNN Buzzfeed EA Sports Ebay Harvard University Samsung Expedia Intuit

Main Competitors:

HipChat Yammer Google Hangouts Facebook at work

Use Case:

Our use case is to send a client their next scheduled appointment to speak with one of our investment advisors if they send a slash command in the appropriate FE channel. The date would have been previously set.

Solution Architecture:

Slack:

Create a slash command (“fngn” in this example). You still wouldn’t have the URL at this point since that will come from AWS. The token below will be copied over to AWS’ lambda function to verify that the request came from the right channel.

AWS:

Create a Dynamo DB with the slack handle as the primary key:

2. Create a lambda function that takes the handle and looks it up in the DB.

3. Create an API gateway to convert the XML format from slack to JSON and vice versa.

Intel Edison + Grove IoT device

Intel Edison is a chip where code can be pushed built for wearables and Internet of Things (IoT) devices. The grove toolkit contains a variety of widgets that can be attached to the Edison board.

Use case:

When motion is detected from the IoT device, send me an email notification.

Solution Architecture:

Grove has a motion detector widget so that was attached to the Edison board.

Intel XDK IoT Edition is the IDE that provides templates to create Nodejs projects and deploy the code for sensors to Edison.

2. From there, it’s just a matter of setting up the SNS service so that every motion detected triggers a publish to the email.

Conclusion

This was a very fun hack. Not only did I find out more information about Twilio, Slack and IoT but it made me realize how easy it is to prototype and possibly productize solutions using the power of AWS. We are now only limited by the power of our imagination.