Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2015 08:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save suzukiken/83ecc611e9ccafad56e6 to your computer and use it in GitHub Desktop.
Amazon Lambda reads S3 bucket information and update IoT Thing's status
import os
import sys
import json
root = os.environ["LAMBDA_TASK_ROOT"]
sys.path.insert(0, root)
import boto3
s3 = boto3.client('s3')
iot = boto3.client('iot-data', region_name='us-east-1')
def lambda_handler (event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
obj = s3.get_object(Bucket=bucket, Key=key)
objlist = s3.list_objects(Bucket=bucket)
payload = {
"state": {
"desired": {
"Count": len(objlist['Contents']),
"Time": obj['LastModified'].strftime('%Y-%m-%D %H:%M:%S')
except Exception as e:
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment