.~c9_invoke_vMHqOd.py [11:41]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def lambda_handler(event, context):
    print("event: {}".format(event))
    client = boto3.client('iot-data')
    deserializer = TypeDeserializer()
    TOPIC = "lambda/operator/input"
    
    # Extending JSONEncoder to convert Decimal()
    class DecimalEncoder(json.JSONEncoder):
        def default(self, obj):
            if isinstance(obj, D):
                return float(obj)
            return json.JSONEncoder.default(self, obj)
    
    for record in event['Records']:
        print(record['eventID'])
        print(record['eventName'])
        if record['eventName'] == 'INSERT':
            newEntry = record['dynamodb']['NewImage']
            data_temp = {k: deserializer.deserialize(v) for k,v in newEntry.items()}
            data_temp["entryId"] = str(uuid.uuid4());
            data = DecimalEncoder().encode(data_temp)
            response = client.publish(
                topic=TOPIC,
                qos=1,
                payload=data
            )
            print("Response ======\n{}".format(response))
    return {
        'statusCode': 200,
        'body': json.dumps('OK!')
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



write_iotcore_from_dynamodb.py [11:41]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def lambda_handler(event, context):
    print("event: {}".format(event))
    client = boto3.client('iot-data')
    deserializer = TypeDeserializer()
    TOPIC = "lambda/operator/input"
    
    # Extending JSONEncoder to convert Decimal()
    class DecimalEncoder(json.JSONEncoder):
        def default(self, obj):
            if isinstance(obj, D):
                return float(obj)
            return json.JSONEncoder.default(self, obj)
    
    for record in event['Records']:
        print(record['eventID'])
        print(record['eventName'])
        if record['eventName'] == 'INSERT':
            newEntry = record['dynamodb']['NewImage']
            data_temp = {k: deserializer.deserialize(v) for k,v in newEntry.items()}
            data_temp["entryId"] = str(uuid.uuid4());
            data = DecimalEncoder().encode(data_temp)
            response = client.publish(
                topic=TOPIC,
                qos=1,
                payload=data
            )
            print("Response ======\n{}".format(response))
    return {
        'statusCode': 200,
        'body': json.dumps('OK!')
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



