如何在本地 PC 上访问模拟的 Azure 存储
How to Access Emulated Azure storage on local PC
我开始使用 Azure 函数进行开发。我已经能够连接到我的实际 azure 存储帐户队列以测试如何使用 Azure 功能进行编程。现在我的下一步是使用 Microsoft Azure 存储资源管理器来使用本地存储帐户,这样我就不必连接到 Azure。我在这篇文章中看到了如何做到这一点:https://docs.microsoft.com/en-us/azure/storage/storage-configure-connection-string#create-a-connection-string-to-the-storage-emulator
in the appsettings.json I changed my values to this exactly:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
"AzureWebJobsDashboard": "",
"StorageConnectionString": "UseDevelopmentStorage=true"
}
}
当我使用 Visual Studio 启动 Azure Fuctions CLI 时,我收到此错误消息:
ScriptHost initialization failed Microsoft.WindowsAzure.Storage: The
remote server returned an error: (403) Forbidden.
有人遇到过吗?
请更改以下代码行:
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
至:
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
或:
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;"
这应该可以解决 403 错误。
基本上,存储模拟器与云存储帐户具有不同的端点。例如,云存储帐户的默认 blob 端点是 http://[youraccount].blob.core.windows.net while the blob endpoint for storage emulator is http://127.0.0.1:10000. When you just specify the storage account name and key for the storage emulator in your connection string, storage client library treats it like a cloud storage account and tries to connect to http://devstoreaccount1.blob.core.windows.net 使用您提供的帐户密钥。由于云中 devstoreaccount1 的密钥不是您提供的密钥,因此您收到 403 错误。
我开始使用 Azure 函数进行开发。我已经能够连接到我的实际 azure 存储帐户队列以测试如何使用 Azure 功能进行编程。现在我的下一步是使用 Microsoft Azure 存储资源管理器来使用本地存储帐户,这样我就不必连接到 Azure。我在这篇文章中看到了如何做到这一点:https://docs.microsoft.com/en-us/azure/storage/storage-configure-connection-string#create-a-connection-string-to-the-storage-emulator
in the appsettings.json I changed my values to this exactly:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
"AzureWebJobsDashboard": "",
"StorageConnectionString": "UseDevelopmentStorage=true"
}
}
当我使用 Visual Studio 启动 Azure Fuctions CLI 时,我收到此错误消息:
ScriptHost initialization failed Microsoft.WindowsAzure.Storage: The remote server returned an error: (403) Forbidden.
有人遇到过吗?
请更改以下代码行:
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
至:
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
或:
"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;"
这应该可以解决 403 错误。
基本上,存储模拟器与云存储帐户具有不同的端点。例如,云存储帐户的默认 blob 端点是 http://[youraccount].blob.core.windows.net while the blob endpoint for storage emulator is http://127.0.0.1:10000. When you just specify the storage account name and key for the storage emulator in your connection string, storage client library treats it like a cloud storage account and tries to connect to http://devstoreaccount1.blob.core.windows.net 使用您提供的帐户密钥。由于云中 devstoreaccount1 的密钥不是您提供的密钥,因此您收到 403 错误。