问题描述
我已经按照说明下载并安装了Linux的Azurite(Ubuntu 18.04)。我想将其与Azure Storage Explorer(也已下载并安装)一起使用,以通过BlobTrigger直观地管理/测试Azure功能。我了解如何启动Azurite,并可以使用Storage Exporer将Blob上传到模拟器容器。
无法确定:
-
如何将Azure Function连接到Azurite容器以用作内部存储。
a。我在
"AzureWebJobsstorage": "UseDevelopmentStorage=true"
中使用了local.settings.json
,但看不到如何将函数连接到Azurite中的给定容器 -
如何将功能连接到具有 BlobTrigger 功能的Azurite容器。
a。我是否需要向
"BlobTrigger": "<azuriteContainerConnectionString>"
添加local.settings.json
设置?
解决方法
基本上,local.settings.json中的值用于保存环境变量。
连接字符串在function.json中声明。如果您使用的是C#或Java之类的语言(需要编译的语言,而不是直接运行),那么它总是有一个声明部分,在编译之后,声明部分将被转换为function.json。
我在本地启动Azurite,然后尝试使用默认的存储帐户:
我获得了Blob服务的默认连接字符串:
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
然后用blobtrigger创建一个C#azure函数:
local.settings.json
{
"IsEncrypted": false,"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx==;EndpointSuffix=core.windows.net","FUNCTIONS_WORKER_RUNTIME": "dotnet","str": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
}
}
Function1.cs
using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([BlobTrigger("test/{name}",Connection = "str")]Stream myBlob,string name,ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}
}
}
似乎很好:
我将AzureWebJobsStorage
设置为azure上的存储,因为使用了10000端口。
这是文档:
https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azurite?toc=/azure/storage/blobs/toc.json