Create Python `BlobClient.from_blob_url` using Azure Storage Emulator?

Solution for Create Python `BlobClient.from_blob_url` using Azure Storage Emulator?
is Given Below:

I’m trying to use the Azure Storage Emulator in the following scenario:

  1. Blob uploaded to Emulated container
  2. Emulated Event Grid message created when blob uploaded
  3. Emulated Queue Storage receives Event Grid message
  4. Locally running Azure Function is triggered from Queue Storage message

Issue:

1 above. Works fine (emulator is up and running)

2 above. Is manual, I don’t want to download and use a third party Event Grid emulator.

  • Instead I create the Event Grid message manually with the name of the uploaded 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"
}
  • Then create a new message in the Emulator Queue Storage and paste it in (basically 3. above)

4 above. The Function triggers but is unable to execute the following piece of code:

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
  • Because the blobUrl of http://127.0.0.1:10000/devstoreaccount1/test/710520200429.csv either isn’t correct or the BlobClient.from_blob_url doesn’t allow a BlobClient to be created from the emulator.

Error:

[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:UserstestAppDataRoamingnpmnode_modulesazure-functions-core-toolsbinworkerspython3.8WINDOWSX64azure_functions_workerdispatcher.py", line 398, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
  File "C:UserstestAppDataLocalProgramsPythonPython38libconcurrentfuturesthread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:UserstestAppDataRoamingnpmnode_modulesazure-functions-core-toolsbinworkerspython3.8WINDOWSX64azure_functions_workerdispatcher.py", line 602, in _run_sync_func        
    return ExtensionManager.get_sync_invocation_wrapper(context,
  File "C:UserstestAppDataRoamingnpmnode_modulesazure-functions-core-toolsbinworkerspython3.8WINDOWSX64azure_functions_workerextension.py", line 215, in _raw_invocation_wrapper    result = function(**args)
  File "C:UserstestDesktopgitAzureFunctionsfa00003fa00003__init__.py", line 132, in main
    credentials = DefaultAzureCredential()
  File "C:UserstestDesktopgitAzureFunctionsfa00003.venvlibsite-packagesazureidentity_credentialsdefault.py", line 123, in __init__
    credentials.append(VisualStudioCodeCredential(tenant_id=vscode_tenant_id))
  File "C:UserstestDesktopgitAzureFunctionsfa00003.venvlibsite-packagesazureidentity_credentialsvscode.py", line 43, in __init__
    validate_tenant_id(self._tenant_id)
  File "C:UserstestDesktopgitAzureFunctionsfa00003.venvlibsite-packagesazureidentity_internal__init__.py", line 40, in validate_tenant_id
    raise ValueError(
.

Can anyone tell me which is correct here?