Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
See: https://qiita.com/ma2shita/items/8f1b4b12faa99dd17063 | Any Lambda function -> this function
"""
`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