def grant_lf_permissions()

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


def grant_lf_permissions(principal_json, table_json, tableWithColumns_json, perm_json, perm_grant_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
            perm_grant_json {dict}        -- grantable permission on 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
        if perm_grant_json:
            perm_with_grant = perm_grant_json['PermissionsWithGrantOption']
        else:
            perm_with_grant = []
        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'],
                                PermissionsWithGrantOption=perm_with_grant)
        logger.info('Grant permissions API response: {}'.format(response))
        return response
    except Exception as e:
        logger.info("lambda Failed")    
        raise e