我尝试在以下场景中使用 Azure 存储模拟器:
- Blob 上传到模拟容器
- 上传 Blob 时创建的模拟事件网格消息
- 模拟队列存储接收事件网格消息
- 从队列存储消息触发本地运行的 Azure 函数
问题:
1 以上。工作正常(模拟器已启动并正在运行)
2 以上。是手动的,我不想下载和使用第三方事件网格模拟器。
- 相反,我使用上传的 blob 的名称手动创建事件网格消息
{
"id": "<long-guid>","data": {
"api": "FlushWithClose","clientRequestId": "<long-guid>","requestId": "<long-guid>","etag": "0x8D9430B96888008","contentType": "application/octet-stream","contentLength": 4633473584,"contentOffset": 0,"blobType": "BlockBlob","blobUrl": "http://127.0.0.1:10000/devstoreaccount1/test/710520200429.csv","url": "http://127.0.0.1:10000/devstoreaccount1/test/710520200429.csv","sequencer": "0000000000000000000000000000933600000000000023c7","identity": "<long-guid>","storageDiagnostics": {
"batchId": "<long-guid>"
}
},"topic": "/subscriptions/<long-guid>/resourceGroups/DEV/providers/microsoft.Storage/storageaccounts/fa00001dev","subject": "/blobServices/default/containers/test/blobs/710520200429.csv","event_type": "microsoft.Storage.BlobCreated"
}
- 然后在 Emulator Queue Storage 中创建一个新消息并将其粘贴到(基本上是上面的 3.)
4 以上。函数触发但无法执行以下代码:
credentials = DefaultAzureCredential()
def create_blob_client(credentials):
try:
blob_client = BlobClient.from_blob_url(eg_msg_json['data']['blobUrl'],credentials,max_single_get_size = 256*1024*1024,max_chunk_get_size = 128*1024*1024)
logging.info(f'####### Successfully created BlobClient #######')
except:
logging.error(f'####### Failed to create BlobClient #######')
logging.error(f'####### Blob URL: {eg_msg_json["data"]["blobUrl"]} #######')
return blob_client
- 因为
blobUrl
的http://127.0.0.1:10000/devstoreaccount1/test/710520200429.csv
不正确或BlobClient.from_blob_url
不允许从模拟器创建BlobClient
。
错误:
[2021-07-31T00:23:01.397Z] ManagedIdentityCredential will use IMDS
[2021-07-31T00:23:01.405Z] Executed 'Functions.fa00003' (Failed,Id=55f8ce9e-08b5-41e2-bd61-d753da0d72e1,Duration=47ms)
[2021-07-31T00:23:01.410Z] System.Private.CoreLib: Exception while executing function: Functions.fa00003. System.Private.CoreLib: Result: Failure
Exception: ValueError: Invalid tenant id provided. You can locate your tenant id by following the instructions here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names
Stack: File "C:\Users\test\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.8\WINDOWS\X64\azure_functions_worker\dispatcher.py",line 398,in _handle__invocation_request
call_result = await self._loop.run_in_executor(
File "C:\Users\test\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py",line 57,in run
result = self.fn(*self.args,**self.kwargs)
File "C:\Users\test\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.8\WINDOWS\X64\azure_functions_worker\dispatcher.py",line 602,in _run_sync_func
return Extensionmanager.get_sync_invocation_wrapper(context,File "C:\Users\test\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.8\WINDOWS\X64\azure_functions_worker\extension.py",line 215,in _raw_invocation_wrapper result = function(**args)
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\fa00003\__init__.py",line 132,in main
credentials = DefaultAzureCredential()
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\.venv\lib\site-packages\azure\identity\_credentials\default.py",line 123,in __init__
credentials.append(VisualStudioCodeCredential(tenant_id=vscode_tenant_id))
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\.venv\lib\site-packages\azure\identity\_credentials\vscode.py",line 43,in __init__
validate_tenant_id(self._tenant_id)
File "C:\Users\test\Desktop\git\Azure\Functions\fa00003\.venv\lib\site-packages\azure\identity\_internal\__init__.py",line 40,in validate_tenant_id
raise ValueError(
.
谁能告诉我这里哪个是正确的?