Last active
April 22, 2021 05:43
-
-
Save anggras/96eb12ef506338e879b8d08d2e300a7b to your computer and use it in GitHub Desktop.
Note: This function access IoT Data Plane directly, not through the usual MQTT protocol. Useful to simulate an IoT device / sensor using Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
import random | |
MAX_TEMP = 42 | |
MIN_TEMP = 36 | |
def lambda_handler(event, context): | |
client = boto3.client('iot-data') | |
temp = round(random.uniform(MIN_TEMP, MAX_TEMP), 2) | |
payload = { | |
'temperature': temp | |
} | |
response = client.publish( | |
topic='test/topic', | |
qos=0, | |
payload=json.dumps(payload) | |
) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment