Azure Functions 和 DataLake gen 2 连接
Azure Functions and DataLake gen 2 connection
我在使用 Azure Functions 和 Azure DataLake Gen2 连接时遇到以下问题:
运行 本地功能一切正常。它连接到数据湖,获取输入文件,处理一些逻辑,然后将修改后的文件上传到数据湖中的新位置。请参阅下面的集成概述:
__init__.py
import logging
import xml.etree.ElementTree as ET
import azure.functions as func
def main(req: func.HttpRequest, inputBlob: func.InputStream, outputBlob: func.Out[func.InputStream]) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
data = inputBlob.read()
xml = ET.fromstring(data.decode('utf-8'))
# for loop here to perform some logic.
outputBlob.set(ET.tostring(xml))
return func.HttpResponse(
"This HTTP triggered function executed successfully.",
status_code=200
)
except ValueError as ex:
return func.HttpResponse(
"Unknown error has occured tih message: " + str(ex),
status_code=400
)
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "blob",
"direction": "in",
"name": "inputBlob",
"path": "https://.xml",
"connection": "APP SETTING NAME"
},
{
"type": "blob",
"direction": "out",
"name": "outputBlob",
"path": "https://.xml",
"connection": "APP SETTING NAME"
}
]
}
- 我正在使用绑定来建立到 inputBlob 和 outputBlob 的连接。
- 我注册了一个APPLICATION SETTING来确保连接(格式:DefaultEndpointsProtocol=https;AccountName=####;AccountKey=####;EndpointSuffix=core.windows.net)。类似于 local.settings.json
运行 触发器我一直收到以下错误:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
我发现了这个:Stack overflow post 说输出绑定不适用于数据湖,但我很困惑为什么本地 运行 可以工作?
有没有人认识到这个问题,如果是的话,对我有解决办法吗?
亲切的问候,
马克
Running the trigger I keep getting the following error:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
当然可以。这是因为你输入绑定的路径不对。
格式应该是这样的:
"path": "containername/foldername1/foldername2/.../filename"
这是input的官方文档:
这是输出:
I found this:Stack overflow post saying outputbindings don't work with
datalakes, but I am confused why the local run works then?
这是一个源于azure function outputbinding的问题,我可以大概描述一下。为什么这么说是因为基于函数outputbinding的包不是datalake包,所以需要在函数体中手动使用datalake服务获取数据。
使用 azure 函数绑定处理数据的后果是您将无法再使用 datalake 包处理文件。
(这个问题一直存在,直到我写下那个答案。)
问题已解决!
未使用输出绑定,但根据文档将逻辑放在函数体中:
https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-file-datalake/samples
我一直收到 404 消息,但通过一些研究,我发现了一个标记为:ClientClosedRequest 的错误。仅出现在 Azure 的 iOS 应用中...
从那里我得出结论 XML 文件太大导致超时..
感谢@bowman Zhu 的指导,让我做了更多的挖掘。
我在使用 Azure Functions 和 Azure DataLake Gen2 连接时遇到以下问题:
运行 本地功能一切正常。它连接到数据湖,获取输入文件,处理一些逻辑,然后将修改后的文件上传到数据湖中的新位置。请参阅下面的集成概述:
__init__.py
import logging
import xml.etree.ElementTree as ET
import azure.functions as func
def main(req: func.HttpRequest, inputBlob: func.InputStream, outputBlob: func.Out[func.InputStream]) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
data = inputBlob.read()
xml = ET.fromstring(data.decode('utf-8'))
# for loop here to perform some logic.
outputBlob.set(ET.tostring(xml))
return func.HttpResponse(
"This HTTP triggered function executed successfully.",
status_code=200
)
except ValueError as ex:
return func.HttpResponse(
"Unknown error has occured tih message: " + str(ex),
status_code=400
)
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "blob",
"direction": "in",
"name": "inputBlob",
"path": "https://.xml",
"connection": "APP SETTING NAME"
},
{
"type": "blob",
"direction": "out",
"name": "outputBlob",
"path": "https://.xml",
"connection": "APP SETTING NAME"
}
]
}
- 我正在使用绑定来建立到 inputBlob 和 outputBlob 的连接。
- 我注册了一个APPLICATION SETTING来确保连接(格式:DefaultEndpointsProtocol=https;AccountName=####;AccountKey=####;EndpointSuffix=core.windows.net)。类似于 local.settings.json
运行 触发器我一直收到以下错误:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
我发现了这个:Stack overflow post 说输出绑定不适用于数据湖,但我很困惑为什么本地 运行 可以工作?
有没有人认识到这个问题,如果是的话,对我有解决办法吗?
亲切的问候,
马克
Running the trigger I keep getting the following error:
<html> <head><title>404 Not Found</title></head> <body bgcolor="white"> <center><h1>404 Not Found</h1></center> <hr><center>nginx</center> </body> </html>
当然可以。这是因为你输入绑定的路径不对。
格式应该是这样的:
"path": "containername/foldername1/foldername2/.../filename"
这是input的官方文档:
这是输出:
I found this:Stack overflow post saying outputbindings don't work with datalakes, but I am confused why the local run works then?
这是一个源于azure function outputbinding的问题,我可以大概描述一下。为什么这么说是因为基于函数outputbinding的包不是datalake包,所以需要在函数体中手动使用datalake服务获取数据。
使用 azure 函数绑定处理数据的后果是您将无法再使用 datalake 包处理文件。
(这个问题一直存在,直到我写下那个答案。)
问题已解决!
未使用输出绑定,但根据文档将逻辑放在函数体中: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-file-datalake/samples
我一直收到 404 消息,但通过一些研究,我发现了一个标记为:ClientClosedRequest 的错误。仅出现在 Azure 的 iOS 应用中...
从那里我得出结论 XML 文件太大导致超时..
感谢@bowman Zhu 的指导,让我做了更多的挖掘。