Sending funny dog GIFs using AWS IoT Button and Lambda

rav3n
4 min readMar 3, 2019

--

I bought an AWS IOT button the other day out of curiosity. I’m not sure on a more permanent solution for it just yet but I’d figured it would do something simple to start.

Goal: Make this button send me funny dog gifs using Lambda. Plus, the infosec community loves dog gifs right??

Fair warning, there is a bit of a set up needed prior to creating the lambda function and connecting the button.

Things you’ll need:

  • Twilio Account SID, Auth Token, and a phone number with MMS capabilities. Check your project settings to get the SID and token. And if you haven’t already, you’ll need to create a project.
  • Giphy API Key from here.
  • AWS IoT Enterprise Button
  • AWS IoT App from app store for iOS or Android
  • Companion Github Files — check out the python source code
  • Your personal phone number to receive the gifs
  • Your Wifi Password

Lambda

Here are the steps I used to create the lambda function via CLI-ish:

# These steps assume you have the correct IAM permissions to do 
# this locally. If not, please check your IAM policies.
# create lambda package, "zip it up & zip it out"mkdir dogbutton
cd dogbutton
virtualenv --python=/usr/local/bin/python3.7 venv
source venv/bin/activate
# install necessary modules
pip install twilio requests giphy_client
deactivate
cd venv/lib/python3.7/site-packages
# create lambda_function.py # <- must be named this
vi lambda_function.py
<copy + paste code from lambda_function.py file in GitHub repo>
zip -r9 lambda_package.zip .
# create lambda # replace aws account number
aws lambda create-function --function-name "dogbutton" --runtime "python3.7" --role "arn:aws:iam::<aws_account_id>:role/lambda_basic_execution" --handler "lambda_function.lambda_handler" --timeout 5 --zip-file "fileb://./lambda_package.zip" --region "us-west-2"
# If you need to update lambda with a newer package, remove the
# previous zip in the same directory, re-zip the package up when
# ready, and re-upload using this:
aws lambda update-function-code --function-name "dogbutton" --zip-file "fileb://./lambda_package.zip" --region "us-west-2"

After the packaged was uploaded, I switched to the console to add the following environment variables:

P.S. Make sure the variables twilio_number and my_number are in the correct format. For me, that meant they followed this format (adding a +1 in front):

“+1<insert_ten_digit_number_altogether>”

Then, I set up and ran the basic test events. If everything is set up properly, you should get a gif texted to your phone.

Now to give this function to an IoT button.

Roll of the sleeves

I logged into the AWS Console and headed over to AWS IOT 1-Click. Under Onboard, then Claim devices, I entered device ID (on the back) of my shiny new button and hit Claim.

While this screen was waiting, I opened the AWS IoT 1-Click App. If you haven’t already, you’ll need to login with your AWS account.

Side Poll: Anyone else having log in fatigue from all the multi-factor logins?

Side Note: It felt a little strange having turn ON my GPS location in order to complete the next step. No dropdown? Enter zip? No?? Bluetooth is needed as well.

I clicked Configure Wi-Fi (have your WiFi password ready!), Manually Enter Device ID, then configure. Follow the instructions from here until you are back on the default screen on the app.

If you switch back to the console, you should see this:

After hitting Done, on the next screen, under Actions, I enabled the button. On the left hand side, I clicked Manage -> Projects.

Here I created a new project and assigned that button to the lambda function created earlier. On Step 1, you’ll name your project and on Step 2, you’ll see the screen below:

After you have created the project, the second to last step is to create a placement and assign the button to this project.

The last step is the best part….. Testing!

If everything is correct, you should receive a funny dog gif via text within 15 seconds after hitting the button. Here is the one I got:

Hope this article has been helpful and thank you for taking the time to read it.

--

--

Responses (1)