def grant_lf_permissions()

in src/lakeformation_permissions/consumption/lambda_function.py [0:0]


def grant_lf_permissions(principal_json, table_json, tableWithColumns_json, perm_json):
    """
      Grants the specified permissions to the Pricncipal on the Respective resources  

      Arguments:
            principal_json  {dict}        -- Principal which requries grant
            table_json       {dict}       -- Resource to grant permissions
            tableWithColumns_json {dict}  -- Resource to grant permissions
            perm_json {dict}              -- permissions that are applied to the resource
    
      Returns:
          response {dict}    -- Response from Lakeformation API call
    """

    logger.info('Granting Lakeformation Permissions ....')
    try:
        resource = {}
        if table_json:
            resource['Table'] = table_json
        elif tableWithColumns_json:
            resource['TableWithColumns'] = tableWithColumns_json
        client = boto3.client('lakeformation', config=Config(connect_timeout=5, read_timeout=60, retries={'max_attempts': 20}))
        response= client.grant_permissions(Principal=principal_json,
                                Resource=resource,
                                Permissions=perm_json['Permissions'])
        logger.info('Grant permissions API response: {}'.format(response))
        return response
    except Exception as e:
        logger.info("Grant permissions Method failed with exception {}".format(e))    
        raise e