def create_thing()

in source/lambda/iot-dr-layer/device_replication.py [0:0]


def create_thing(c_iot, c_iot_primary, thing_name, thing_type_name, attrs):
    logger.info('create_thing: thing_name: {} thing_type_name: {} attrs: {}'.
        format(thing_name, thing_type_name, attrs))
    try:
        if not thing_exists(c_iot_primary, thing_name):
            logger.warning(
                'thing_name "{}" does not exist in primary region "{}", will not being created'.
                format(thing_name, c_iot_primary.meta.region_name))
            return

        if not thing_exists(c_iot, thing_name):
            if thing_type_name and attrs:
                logger.info('thing_name: {}: thing_type_name and attrs'.format(thing_name))
                create_thing_type(c_iot, thing_type_name)
                response = c_iot.create_thing(
                    thingName=thing_name,
                    thingTypeName=thing_type_name,
                    attributePayload=attrs
                )
            elif not thing_type_name and attrs:
                logger.info('thing_name: {}: not thing_type_name and attrs'.format(thing_name))
                response = c_iot.create_thing(
                    thingName=thing_name,
                    attributePayload=attrs
                )
            elif thing_type_name and not attrs:
                logger.info('thing_name: {}: thing_type_name and not attrs'.format(thing_name))
                create_thing_type(c_iot, thing_type_name)
                response = c_iot.create_thing(
                    thingName=thing_name,
                    thingTypeName=thing_type_name
                )
            else:
                logger.info('not thing_type_name and not attrs')
                response = c_iot.create_thing(
                    thingName=thing_name
                )
            logger.info('thing_name: {}: create_thing: response: {}'.format(thing_name, response))
        else:
            logger.info('thing_name: {}: thing exists already'.format(thing_name))
    except Exception as e:
        logger.error('thing_name: {}: create_thing: {}'.format(thing_name, e))
        raise DeviceReplicationCreateThingException(e)