Last active
November 7, 2018 14:24
-
-
Save ma2shita/f4973cc64e28fd24234450139c7fa8f6 to your computer and use it in GitHub Desktop.
See: https://qiita.com/ma2shita/items/8f1b4b12faa99dd17063 | Any Lambda function -> this function
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
""" | |
`event` is; | |
{ | |
"transition_wating_sec": <sec:Integer>, | |
"thing_name": <thingName:String> | |
} | |
""" | |
import json | |
import logging | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
import time | |
import boto3 | |
def lambda_handler(event, context): | |
logger.info('Received event: ' + json.dumps(event)) | |
time.sleep(event['transition_wating_sec']) | |
s = event.get('transition_to', 'idle') | |
shadowDoc = {'state':{'reported':{'status':s}}} | |
iot = boto3.client('iot-data') | |
iot.update_thing_shadow(thingName=event['thing_name'], payload=json.dumps(shadowDoc)) | |
return {"statusCode": 204} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment