AWS Public Sector Blog

Grandma Emergency Button: A simple emergency alert solution with AWS IoT Button

My grandma is 88 years old with reduced mobility. She lives alone, without a caretaker, in a small village. If she falls, then she is in danger. If something goes wrong when she’s in bed, she might need assistance. With an AWS IoT button, she can call for help in a simple way that could potentially save her life.

Her village provides free Wi-Fi coverage, so I built an emergency alert system using AWS. When she clicks the AWS IoT button, a series of events will take place to get her the assistance she needs. This can help her in difficult situations. It’s a solution that others can create as well. In this blog post, I’ll show you how to get started.

Start building – Setting up the button

The first step is to set up and register the AWS IoT button in the AWS IoT service platform. In the AWS Management Console, navigate to the AWS IoT console. In the left navigation pane, choose Manage.


On the Manage page, register a new “thing” by following the instructions in the “Register a Device in the Registry” documentation. To finish setting up the button, follow the step-by-step guide. You can also use the Android or iOS app for the set up.

After the button is configured when you press it, the light will blink blue and then will turn green showing it was able to connect to the AWS IoT service. You are now ready to use it!

Overall description and architecture

After my grandma clicks the AWS IoT button, we will call her landline phone automatically and request her to press 1 to deactivate the alarm (in case she clicked the button by mistake). If it was not a mistake, and she doesn’t answer the call or press “1,” then we will call her relatives (me) to alert them, because this may be a potentially risky situation.


The following architecture diagram shows the AWS services I used:


AWS Lambda functions and Amazon DynamoDB are the main services I used. After the button is clicked, the event will trigger a set of AWS Lambda functions that will update Amazon DynamoDB with the alarm activation through a workflow in AWS Step Functions. Within the workflow, Amazon Connect will call grandma and her relatives.

The second phase is the predictive prescription. The data in Amazon DynamoDB from the alarm’s activation combined with other external data (time of the action, temperature, and moon phase) will be used to create a predictive model.

Amazon SageMaker will help us to create this model, train it, and set up the endpoint to obtain predictions.

Grandma pressed the button, let’s call her.

When the button is clicked, we need to start a Lambda function to update Amazon DynamoDB with the alarm activation data. The update includes an important flag to indicate that the alarm is active. The Lambda function will also make the initial call to grandma.

Sample code for the function can be seen here. The code uses the Amazon Connect API StartOutboundVoiceContact action to make the outbound call to grandma. Please follow the Amazon Connect set-up guide to create your instance if you don’t have one.

Other API calls in the code are done through the Python requests module. These obtain moon phase and weather information. For example, I used the Naval Oceanography Portal that provides a free API for moon data. For weather, I used the Dark Sky API.

Is the alarm real or a mistake?

The button was clicked, the initial call is made, and now the alarm system logic progresses into Amazon Connect. Amazon Connect uses “contact flows” to handle the calls and their interactions. We need to create the appropriate contact flow to handle the initial call. Flows are created using building blocks within the visual editor. The full description of blocks available is here.

A sample contact flow for the alarm system can be seen in the following figure:

The main actions performed in the flow are:

  • Providing an automated speech when grandma picks up the phone. In this case, something like: “Attention, alarm has been activated, press 1 to deactivate.”
  • Checking if she presses “1” or not. To do so, we need to introduce a block to listen to her input – the “Get customer input” block. We will branch, depending on what was pressed or not.

If she presses “1,” we need to deactivate the alarm by introducing a call to a Lambda function. The function will update the Amazon DynamoDB alert’s active flag. We will do that with a block called “Invoke AWS Lambda function.” If she does not press “1,” we will progress in the logic of the alert system, calling her relatives.

A sample of the code for the Lambda function to associate to the Amazon Connect block can be found here.

What if grandma does not pick up the phone?

The Amazon Connect API used to make the outgoing calls does not provide us with any indication whether the call was answered or not. We will deactivate the alarm if she picks up the call and presses “1.” If she does not, we know we have to call her relatives. However, what if she doesn’t answer the call? How does the system know if the activation was real or a mistake?

We will set a flag in Amazon DynamoDB when grandma presses the button. The flag will be a parameter named CallActive set to “Y” in the alarm’s associate data within Amazon DynamoDB. The system logic will unfold based on that parameter’s value.

Let’s call her relatives.

After the initial call to grandma’s landline, unless she picks up the phone and presses “1,” the CallActive parameter will remain set to “Y,” unchanged. If “1” is pressed, the CallActive parameter will be set to “N.” See a possible example in the following figure:


We need to introduce a check to verify if the alarm is active or not after the initial call. If it is still active, proceed the call to the relatives. With AWS Step Functions, we can define a state machine that will execute those steps. The following is an example of a state machine definition that we can use:

When the state machine starts it will call the Lambda function to perform the initial call to grandma and update the Amazon DynamoDB table with an active alert (the parameter CallActive set to “Y).

In the second step, we wait for the call to occur with a wait condition. Logic is in the Amazon Connect contact flow where grandma can press “1” to deactivate the alarm. In the third step, a check is performed against the CallActive flag.

This link provides a possible Lambda function for the third step, in which the flag is checked and a call to relatives is made if appropriate. We need to create another contact flow for the call to relatives. We will use the “Play Prompt” block again with a speech, like: “Your relative has activated the alarm, please act accordingly.”

We can cycle over the state machine steps as many times as necessary. See the AWS Step Functions documentation, topic Iterating a Loop Using Lambda.

Connecting the AWS IoT button and Step Functions

The last stage of the project is to connect the AWS IoT button with the services we have described. So, when grandma clicks the button, the alarm system gets activated.

The AWS Step Functions state machine that we created will orchestrate the Lambda function call, the Amazon Connect interaction, and the entire alarm system. We need to start the AWS Step Function state machine when grandma clicks the button.

The AWS Lambda function that will kick off the state machine when grandma clicks the button is the StartExecution API action. To learn more, see the AWS Step Functions documentation on the Start Execution API, It should be a simple call using the Amazon Resource Name (ARN) of the state machine we have defined.

To finish and link the AWS IoT Button with this Lambda function, you must define a trigger for the Lambda function in the AWS Lambda console. The trigger must be the click of the AWS IoT button.

For more information on creating this type of trigger, see Creating a Lambda Rule in the AWS IoT documentation.

We have shown you how to build a system that will help many people (including my grandma) in different situations. We use a simple and open approach – click a button, start a set of AWS services, and use simple Python code. In the second phase of the project, we will attempt to provide a predictive prescription by creating a prediction model after we have enough data to train a model.

We hope this post was useful and helped you get started creating new services or applications with the AWS IoT button.

Check out some of my other blog posts on the AWS Public Sector Blog, including, “Creating a serverless GPS monitoring and alerting solution,” “Automating fall detection with AWS DeepLens,” “Using a serverless architecture to collect and prioritize citizen feedback,” and “Develop and extract value from open data.”

Subscribe to the AWS Public Sector Blog newsletter to get the latest in AWS tools, solutions, and innovations from the public sector delivered to your inbox, or contact us.