AWS Startups Blog

Using AWS IoT to Reduce Waste

Post by Trevor Hillis, Commercial Sales Rep, AWS

About two months ago, I purchased an AWS IoT button (a programmable physical button that integrates with AWS services) with the hope of learning a little bit more about IoT (Internet of Things) and programming. I don’t come from a technical background, have virtually no experience with programming or IoT, and figured the hurdles to building something functional, much less useful, would take months to overcome. The button sat idle on my desk until last week, and within a few days of committing to building something I had programmed a button that helped our office reduce waste by alerting an email alias whenever there was leftover food in the kitchen. With the documentation available on the website and the sample code on the AWS Github account, anyone, regardless of technical abilities, can program an IoT button in an afternoon.

I work in a building with roughly 400 other employees, and the main kitchen is 11 floors below me. It’s not uncommon for leftover food to be put out in the kitchen, especially with Amazon’s recent acquisition of a San Francisco startup in my building that serves pretty generous lunch portions. The only issue is awareness, as no one knows when there is or isn’t food in the kitchen. This can create an inefficient and wasteful surplus. No one has time to constantly check whether there is food in the kitchen, and even if someone stumbles across it, there is no efficient way to communicate that info with others in the building. With the IoT button, when someone notices leftover food all it takes is one press of the button for the entire building to get a notification, which helps us get free lunch. More important, it significantly decreases the amount of waste that we produce!

Programming the button

To build something similar, all you need is an IoT button and an AWS account. The IoT button starts at $14.99 and the AWS usage falls under the free tier limits for the first year, so this is a very cost-effective way to learn about AWS and to be inventive. Once your free tier expires, you’d have to press the button 5 million times in a month, so two times every second for 31 days straight, just to incur $1 in request fees. The AWS services I used are AWS Lambda, AWS IoT, and Amazon Simple Notification Service (SNS). The IoT button acts as the trigger for the code. The code resides in a Lambda function, which tells SNS to send an email. I was pretty unfamiliar with these services before building the button, but I learned how to use them by following the simple steps in the AWS IoT Developer Guide.

First, I created an SNS topic and subscribed the office email alias to that topic so that SNS could publish messages to the email alias. Amazon SNS is a simple push notification service that allows you to affordably send texts or email notifications to Apple, Google, Fire OS, and Windows devices worldwide.

Configuring the AWS IoT Button

After I created a topic, I selected the check box next to the topic. I chose Actions, and then I chose Subscribe to topic. For Protocol, I chose email, and for Endpoint I typed the email alias that I wanted to send the notifications to.

EndPoint settings

Next, I programmed a Lambda function to publish a “NomNom Alert—Food in Kitchen” message to the SNS topic after the function was triggered. AWS Lambda is a service that manages provisioning infrastructure for you, so all you have to do is upload your code and Lambda handles everything else involved with running and scaling the code. You can even write and edit the code inline from the AWS Lambda console. I added an IoT trigger to the Lambda function, then specified the IoT button by entering the serial number and selecting Enable trigger.

Enabling IoT Button trigger to Lambda

The code for the Lambda function is simple JavaScript that publishes content to a resource identified by the ARN (Amazon Resource Name), which in this case was the SNS topic I created. You can even use a simple if statement to configure the button to publish different messages based on different “events.” In my case, I used a single vs. double click of the button. The double click sends a message that the food available isn’t vegetarian friendly. (The office is in San Francisco, after all).

The following sample code is posted on the awslabs GitHub account here, so to implement this yourself all you need to do is go to the AWS Lambda console in your AWS account, choose Create a Lambda function, choose Blank Function, and paste the code from the GitHub account into the Lambda code editor.

Sample code from AWS Labs GitHub account

Remember to edit the ARN to the SNS topic you created and to add the IoT button as the Lambda trigger. You could use this in a variety of ways, like having a Lambda function post as a bot on a Slack channel. The implementation is completely up to you!

For my implementation, whenever there is leftover food in the office kitchen, someone presses the IoT button, which triggers the Lambda function, which publishes the free food message to the SNS topic, which sends that message to the office alias. Everyone on the alias immediately gets an email notification that there is food in the kitchen.
AWS IoT Button architecture

While the benefit of being aware of free food is nice, the greater benefit of knowing that we are decreasing the amount of waste we produce is even better. America wastes approximately 35 million tons of food per year, and it’s nice to know that a simple use of technology can help us put a very, very small dent in that number. The applications of an IoT button are virtually endless, and the real opportunity lies in extending the use of the button to further decrease waste, feed the homeless, or assist in whatever cause you are passionate about. That’s the best part of the button—what you create is up to you. We look forward to seeing what you do with it!


Interested in other projects? Check out the AWS Startup Kit, Amazon Rekognition and more on the Startups blog!