def record_device_info()

in provisioning_lambda/lambda_function.py [0:0]


def record_device_info(dsn, cert_arn, thing_info):
    table = boto3.resource('dynamodb').Table(os.environ['DDB_TABLE'])
    item = table.get_item(Key={'dsn': dsn})
    if 'Item' not in item:
        response = table.put_item(Item={'dsn': dsn, 'certificateArn': cert_arn, 'thingInfo': thing_info})
    else:
        response = table.update_item(
            Key={'dsn': dsn},
            UpdateExpression='SET certificateArn = :certificateArn, thingInfo = :thingInfo',
            ExpressionAttributeValues={':certificateArn': cert_arn, ':thingInfo': thing_info}
        )
    if response['ResponseMetadata']['HTTPStatusCode'] != HTTPStatus.OK.value:
        logger.error('Fail to update device (%s), certificateArn (%s)', dsn, cert_arn)