freshidea - Fotolia


Push the AWS IoT Button for noncritical tasks

While the AWS IoT Button is useful for many simple tasks, developers shouldn't tie the device to security-sensitive operations and should keep an eye on battery life.

AWS IoT allows enterprises to build internet of things applications and devices. IT teams can use it for almost...

anything -- from controlling lights and garage doors to tracking high-value packages, or even automating work for employees. The AWS IoT Button is a quick way to trigger any AWS Lambda function a developer creates. Let's look at an example of how to use it every day, and then dive into its functionality.

When I start my workday, I come into the office and tap the AWS IoT Button. This button push starts a Toggl timer and notifies co-workers via Flowdock that I am checking in for the day. At lunch, I tap it again, and it automatically pauses the timer and notifies co-workers of the change. The same process occurs when I return from lunch, and then I tap the button twice to indicate I'm leaving at the end the day.

So, what's happening behind the scenes? Each tap on the AWS IoT Button sends a secure transmission through Wi-Fi to AWS IoT, which then triggers a custom AWS Lambda function. Developers configure that Lambda function to do what they want. In my case, the function checks to see if there is an active Toggl session. If so, it stops it and indicates in Flowdock that I'm leaving. If not, it starts a new session and indicates in Flowdock that I'm available. It interacts with both of these tools using REST APIs.

The AWS IoT Button uses Secure Sockets Layer (SSL) certificates to securely connect to the AWS IoT framework, which makes the button safe to use, even in nonsecure networks. Developers configure the AWS IoT button over Wi-Fi. During the initial setup, the button creates an ad hoc network that developers connect to from their desktops. This serves up an HTTP page, with configuration options for both the network and AWS IoT. Before doing this, obtain the AWS IoT settings from the Amazon console, which includes downloading the SSL certificates the button uses to connect back to Amazon.

The AWS IoT Button comes with a quick-start tutorial that guides developers through the setup process. A developer can perform three different types of taps: single tap, double tap or long tap. I use double tap to indicate when I start or end the day; I use a single tap to indicate breaks. The long tap can be troublesome -- if you hold the button too long, it enters setup mode. So, it's best to avoid long tap.

Responding to push events

Once the initial IoT setup is complete, every button-push event sends to the custom, configured Lambda function to the setup process. The event will contain a clickType, which will be either SINGLE, DOUBLE or LONG. It also contains information about the status of the battery, and developers can set up low-battery alerts.


    "serialNumber": "SOMECHARACTERS",

    "batteryVoltage": "1781mV",

    "clickType": "DOUBLE"


The AWS IoT Button comes with a quick-start tutorial that guides developers through the setup process.

The Lambda function can do anything that's possible with code, but the button will not wait for the callback to complete. So, it's not currently possible to change the status indicator based on feedback from the Lambda function.

It's important to note that the AWS IoT Button press isn't immediate; it can take five to 10 seconds before the Lambda function fires. Therefore, it isn't recommended for functions that require immediate feedback, such as opening a door or disabling an alarm. The button itself has a small LED that blinks blue when it issues the command and turns green once it submits the request. There's no feedback on the response from the Lambda function -- return a successful response, not an error, or the Lambda function may execute again until it runs successfully.

Testing the AWS IoT Button

As of now, the battery in the button isn't replaceable or rechargeable, and it's only good for about 1,000 presses. At my average of four button presses every day, I'll need to buy an entirely new button in less than a year. During initial testing, it's not a good idea to click away to test minor changes to the Lambda function. It's easy to waste 50 button pushes testing minor updates, which quickly chews up battery life.

Developers can test the button in two ways after confirming that it is firing the Lambda function. The simplest is through the Lambda console, which allows developers to execute a test event. Developers can simply use a sample event that includes a clickType with the type of event that they wish to test.

The second way to test a button click is by using MQTT within an AWS IoT client. Choose Resources and then select your AWS IoT Button thing. Look for the name, which should look something like iotbutton_SOMECHARACTERS. Copy this, and then choose the MQTT client at the top.

Click on Generate ID, then Connect, and then choose Publish to topic and paste that into the IoT Button name, replacing the underscore with a slash to make it iotbutton/SOMECHARACTERS.

Finally, type in the payload of something like: { "clickType": "SINGLE" } to indicate a single-button click. When you're ready to do a full end-to-end test, trigger the Lambda function by clicking the button directly.

What else could you do with an IoT button?

The AWS IoT Button is best suited for automation projects that aren't destructive. For example, a developer wouldn't want the button to stop servers or issue a payment of some sort, because the process is only as secure as the button location. It's not a fingerprint sensor, so a developer wouldn't want it to turn off an alarm or unlock a door. And because it's within the AWS IoT infrastructure, it doesn't need to execute a Lambda function.

It could also interact directly with other AWS IoT devices, such as lights, window shades or anything else that a developer connects to using an MQTT client. Stick to items that are informational in nature -- nothing that would be pressed more than a few times daily.

Next Steps

AWS aims for new customers with Lumberyard, IoT Button

AWS IoT offers a world of possibilities

Connect IoT devices to the AWS cloud

Dig Deeper on AWS tools for development