我已经设置了一个单独的测试环境来尝试从 azure 密钥保管库中检索应用程序机密。当测试函数运行以返回环境变量时,应用程序设置中的 @Microsoft.KeyVault(...) 引用未解析为引用的机密或文本。
按照此文档创建应用服务并根据密钥保管库对其进行身份验证,我为我的函数创建了一个托管标识,将其添加到 AAD,为此托管标识创建了一个特定的访问策略,并在我的密钥保管库中使用 Get Secret 范围,并尝试使用/不使用应用程序作为用户启用读取范围。
运行诊断工具来解析函数应用应用程序设置引用不会产生任何错误。输入应用程序设置为@Microsoft.KeyVault(SecretUri=SecretUri)
或者
@Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret;SecretVersion={version})
Run Code Online (Sandbox Code Playgroud)
似乎没有改变任何东西。我等待了长达半小时的设置更改以在 Azure 中复制并确保我所做的更改是持久的。
这是我返回环境变量的函数应用程序(用python编写):
import json
import logging
import os
import azure.functions as func
def main(req=None) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
name = [os.environ["CLIENTID"]]
except:
name=dict()
for d in os.environ:
name[d]=os.environ[d]
if name:
return func.HttpResponse("Params\n{}".format(json.dumps(name, sort_keys=True, indent=4)))
else:
return func.HttpResponse(
"Please pass a name on the query string or in the request body",
status_code=400
)
Run Code Online (Sandbox Code Playgroud)
我希望能够提取环境变量 CLIENTID。相反,获取该变量失败并返回所有环境变量。如果我无法返回单一变量,我会故意返回所有环境变量,因为我想确保在变量重命名或存在键入/区分大小写问题时捕获了它。
将队列触发函数定义为以下示例:
public async Task OrchestratorAsync(
[QueueTrigger("my-queue", Connection = "")]string payload,
[OrchestrationClient] DurableOrchestrationClient orchestrationClient)
{
//Do something
}
Run Code Online (Sandbox Code Playgroud)
csproj 文件看起来像以下详细信息,并且编译成功:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
</ItemGroup>
</project>
Run Code Online (Sandbox Code Playgroud)
当我升级Microsoft.Azure.WebJobs.Extensions.DurableTask到 2.0.0 版时,编译器会在无法找到 OrchestrationClient 和 DurableOrchestrationClient 时抛出错误。所以我们坚持使用 1.8.2 版!这个问题的解决方案是什么?
注意:这个问题在 VS 2019 中可以重现。让它搭建一个 Function 项目,创建另一个函数作为一个持久的编排器,调整 csproj 文件并将 DurableTask nuget 包版本从默认的 1.8.2 提高到 2.0.0。
我有以下用 Python 编写的简单 Azure 函数。它是一个 HTTP 触发器,它应该简单地返回来自 Azure 存储帐户的 blob 输入绑定的名称和 URI(此处为 Microsoft 的参考文档)。
import logging
import azure.functions as func
import azure.storage.blob
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
def main(req: func.HttpRequest, inputblob: func.InputStream) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
return func.HttpResponse(f"Blob name: {inputblob.name}. Blob URI: {inputblob.uri}")
Run Code Online (Sandbox Code Playgroud)
我的 function.json 文件看起来像这样。我已经验证 local.settings.json 中的连接字符串是正确的,并且 blob 路径也是正确的。
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"name": …Run Code Online (Sandbox Code Playgroud) 我创建了一个 Azure 函数,并希望能够在该函数的 Python 代码中使用各种包;以 Numpy 为例。显然,代码一旦发布到 Azure 就不会在我的本地机器上运行。这意味着我无法将 Numpy 安装到它运行的任何基础架构上,因此我无法在我的代码中导入 Numpy。如何在代码中使用像 Numpy 这样的包?
我正在使用Azure Media Services v3一个Azure Function v3应用程序,并在尝试从 https url 创建新作业时遇到问题。
我在Azure Function提交作业中有以下方法。
private static async Task<Job> SubmitJobAsync(IAzureMediaServicesClient client, string transformNam, string jobName, string fileUrl) {
JobInputHttp jobInput = new JobInputHttp(files: new [] { fileUrl });
JobOutput[] jobOutputs =
{
new JobOutputAsset(jobName)
}
Job job = await client.Jobs.CreateAsync(
_resourceGroupName,
_accountName,
transformName,
jobName,
new Job
{
Input = jobInput,
Outputs = jobOutputs
},
CancellationToken.None);
return job;
}
Run Code Online (Sandbox Code Playgroud)
它在实际创建作业的线路上失败,await client.Jobs.CreateAsync(...
并返回一个带有以下消息的异常:
操作返回了无效的状态代码“BadRequest”
堆栈跟踪:
在 Microsoft.Azure.Management.Media.JobsOperations.CreateWithHttpMessagesAsync(String resourceGroupName, String …
我有以下local.settings.json文件:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"SureMdmApiKey": "xxx",
"SureMdmApiUrl": "xxx",
"SureMdmUsername": "xxx",
"SureMdmPassword": "xxx"
},
"ConnectionStrings": {
"StorageConnectionString": "aaaa",
"DataContext": "aaaa"
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在 Startup.cs 文件中有以下代码:
[assembly: FunctionsStartup(typeof(FunctionAppSureMdmSync.Startup))]
namespace FunctionAppSureMdmSync
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var services = builder.Services;
services.AddTransient<ISureMdmService>(s => new SureMdmService(
url: System.Environment.GetEnvironmentVariable("SureMdmApiUrl"),
username: System.Environment.GetEnvironmentVariable("SureMdmUserName"),
password: System.Environment.GetEnvironmentVariable("SureMdmPassword"),
apiKey: System.Environment.GetEnvironmentVariable("SureMdmApiKey")
));
var connString = System.Environment.GetEnvironmentVariable("ConnectionStrings:DataContext");
services.AddDbContext<DataContext>(options => options
.UseSqlServer(connString, x => x.UseNetTopologySuite()));
services.AddTransient<ITabletGroupService, …Run Code Online (Sandbox Code Playgroud) 我想有一些方法,如何上传文件(可以是没有 php 的 html,或者一些交互式的 azure 上传页面,等等),并通过我的 URL 参数发送参数,该参数将运行其余的代码使用这个上传的文件(ofc 我至少需要将它保存到 blob)。
我需要一个 rest api,所以我选择了 azure 函数。
有没有办法在python中做到这一点?我在 C# 中看到了很多示例,但是 Python 的文档有限。
多谢!
我想在不同的环境(测试、验收、生产)中部署我的 Azure Function App。这是一个时间触发的函数,每晚在生产中运行。然而,当我测试和调试它时,即当它在 Dev 和 Acc 环境中运行时,我不想要这个。目前,我的计时器属性如下:
public class TimedAzFunction
{
// CTOR
public TimedAzFunction()
{
}
// How to set the timer (using CRON notation):
// "0 30 3 * * 1-5" for prod
// Runs every 5 mins: "0 */5 * * * *" for dev and acc
[FunctionName("TimedAzFunction")]
public async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
// Code for function here
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这意味着我要发布它时必须手动更改它,这很容易出错。
我尝试使用本地设置做一些事情并评估该值,然后创建一个 TimerTrigger 对象,但这不起作用。如何根据运行环境设置计时器,例如使用AZURE_FUNCTIONS_ENVIRONMENT和 …
我有一个 Azure Function App,其 URLhttp://localhost:7072/api/create-room处有一个函数以及其他函数。这个特殊的函数是HTTPTrigger允许匿名访问并接受GET动词:
[HttpTrigger(AuthorizationLevel.Anonymous, "get")]
Run Code Online (Sandbox Code Playgroud)
除此之外,我还有一个单独的函数应用程序,它仅托管一个proxies.json文件并且仅用作函数代理。我的代理功能在7071本地端口上运行。
我的代理文件目前看起来像这样:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"chatNegotiate": {
"matchCondition": {
"route": "/api/chat/negotiate",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/BeginNegotiate"
},
"chatMessages": {
"matchCondition": {
"route": "/api/chat/messages",
"methods": [
"POST"
]
},
"backendUri": "%chat_api%/api/PostMessage"
},
"createRoom": {
"matchCondition": {
"route": "/api/create-room",
"methods": [
"GET"
]
},
"backendUri": "%session_api%/api/CreateRoom"
}
}
}
Run Code Online (Sandbox Code Playgroud)
When both of these function apps are deployed to Azure, everything works …
我正在尝试使用托管标识通过 azure 门户访问 Azure Function。如果我使用系统分配的身份,下面的代码行效果很好。
[FunctionName("FunctionDemo")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
ILogger log)
{
log.LogInformation("Starting to get accessToken through client id");
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/")
return req.CreateResponse(HttpStatusCode.OK);
}
Run Code Online (Sandbox Code Playgroud)
azure-functions ×10
azure ×8
c# ×2
python ×2
.net-core ×1
asp.net-core ×1
azure-sdk ×1
localhost ×1
proxy ×1
python-3.6 ×1
rest ×1