def create_registry_event()

in source/lambda/iot-dr-region-syncer/iot-region-to-ddb-syncer.py [0:0]


def create_registry_event(c_iot_s, c_dynamodb, thing, account_id):
    global NUM_THINGS_EXIST, NUM_ERRORS
    logger.info('thing: {}'.format(thing))
    try:
        thing_name = thing['thingName']

        if SYNC_MODE == "smart":
            if thing_exists(c_iot_s, thing_name):
                logger.info('thing_name {} exists already in secondary region {}'.format(thing_name, c_iot_s.meta.region_name))
                NUM_THINGS_EXIST += 1
                return

        # "uuid": "{}".format(uuid.uuid4()),
        event = {
            "uuid": "{}".format(hashlib.sha256(thing_name.encode()).hexdigest()),
            "accountId": str(account_id),
            "expires": int(time.time()+172800),
            "eventType" : "THING_EVENT",
            "eventId" : "{}".format(uuid.uuid4()),
            "timestamp" : int(time.time()*1000),
            "operation" : "CREATED"
        }

        event['thingName'] = thing_name

        thing_type_name = ""
        if 'thingTypeName' in thing:
            thing_type_name = thing['thingTypeName']
            event['thingTypeName'] = thing_type_name

        attrs = {}
        if 'attributes' in thing:
            event['attributes'] = {}
            for key in thing['attributes']:
                event['attributes'][key] = thing['attributes'][key]

        logger.info('thing_name: {} thing_type_name: {} attrs: {}'.format(thing_name, thing_type_name, attrs))

        update_event(c_dynamodb, json.loads(ddb_json.dumps(event)))
    except Exception as e:
        logger.error("update_table_create_thing_error: {}".format(e))
        NUM_ERRORS += 1