首页 > 解决方案 > Azure Powershell Function App 从 Data Lake Gen 1 读取内容

问题描述

对于这个问题的任何帮助,我将不胜感激。

我要做的就是使用一个简单的 Azure 函数应用程序,使用 Powershell 从我的数据湖中读取文件(“/input/specimen.json”),使用它,然后最终将其写回湖中。我已经被困住了。

以下是函数应用程序中的相关代码:

# The below line is at the very top of the function app run.ps1
using namespace System.Management.Automation.PSCredential

# The lines below are in the main area of the function app which are called.
$path = "/input/specimen.json"
$account = "mydatalake"

$tenant = "<my-tenant-id>"
$user = "<application/client id>"
$pass = "<client secret>"

$password = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $user,$password

connect-azaccount -credential $cred -tenant $tenant -ServicePrincipal

$data = Get-AzDataLakeStoreItemContent -accountname $account -path $path
write-host $data

$body = $data | out-string
disconnect-azaccount

函数应用的输出是:

2020-06-04T19:49:09Z [错误] 错误:Get-AzDataLakeStoreItemContent:打开文件 /stan/interests.json 的读取流时出错。操作:GETFILESTATUS failed with HttpStatus:Forbidden RemoteException: AccessControlException GETFILESTATUS failed with error 0x83090aa2(禁止。ACL 验证失败。资源不存在或用户无权执行请求的操作。)。[a6cfab98-149a-46eb-8cb6-b​​d0a40a11796] 失败,错误为 0x83090aa2(禁止。ACL 验证失败。资源不存在或用户无权执行请求的操作。)。[a6cfab98-149a-46eb-8cb6-b​​d0a40a11796][2020-06-04T12:49:08.1314705-07:00] JavaClassName:org.apache.hadoop.security.AccessControlException。

ACLS 和权限的错误,但我已经设置了一个服务主体以用于“connect-azaccount”,并使该 SP 既是数据湖的贡献者又是所有者,但仍然得到相同的错误。我有理由确定我正在使用的 SP 正在用于身份验证,因为 Function App 日志显示创建的会话正在使用正确的租户和客户端 ID 回显到主机。

这开始让我发疯了。我还需要什么才能让它工作?是否需要其他角色或权限?有一个更好的方法吗?

任何和所有的帮助将不胜感激 - 在此先感谢。

标签: azureazure-functionsazure-powershellazure-data-lake

解决方案


如果要使用服务主体访问 Azure 数据湖 gen1 文件,我们需要从 sp.config 配置 ACL。更多详细信息,请参阅文档

Azure 数据湖 gen1 的 ACL 具有三个权限。有读、写和执行。有关详细信息,请参阅文档在此处输入图像描述

例如,我们要读取文件/Oregon/Portland/Data.txt,我们需要配置 ACL 如下 在此处输入图像描述

关于如何配置,我们可以在 Azure Portal 上进行 在此处输入图像描述


推荐阅读