标签: azure-functions

Function App 未读取 Azure Functions v4 中包含用户机密的 local.settings.json 文件

我环顾四周,很惊讶没有人问过这个问题,但我正在尝试将用户机密与我的 Azure Function 应用程序(.NET 6,v4)一起使用。该值永远不会填充“我从 Visual Studio 本地运行”。

Function1.cs

public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var secret = Environment.GetEnvironmentVariable("mysecret");

            return new OkObjectResult($"Secret is: {secret}");
        }
    }
Run Code Online (Sandbox Code Playgroud)

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}
Run Code Online (Sandbox Code Playgroud)

secrets.json

{
  "mysecret": "test1",
  "Values:mysecret": "test2"
}
Run Code Online (Sandbox Code Playgroud)

FunctionApp1.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <UserSecretsId>24c7ab90-4094-49a9-94ef-c511ac530526</UserSecretsId>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
  </ItemGroup>
  <ItemGroup> …
Run Code Online (Sandbox Code Playgroud)

.net c# visual-studio azure-functions .net-6.0

1
推荐指数
1
解决办法
6423
查看次数

如何从 .net core 6 记录应用程序洞察

我有一个包含 2 个项目的解决方案:

  1. 函数应用程序项目
  2. web api .net core 6.0项目

函数应用程序成功记录到应用程序见解,但 Web api 项目却没有!Azure 门户显示这两个项目都配置为写入应用程序见解的同一实例。

两个不同的资源写入同一个应用程序见解实例是否存在问题?如果不是,我做错了什么?

c# azure-application-insights azure-functions .net-6.0

1
推荐指数
1
解决办法
8417
查看次数

如何访问 Azure Function Independent Worker 服务配置中的用户密钥值?

在我的函数应用程序(.NET 7.0,独立工作线程)中,我有一个使用 API 密钥的特定依赖项,该依赖项需要放入秘密存储中。我正在使用用户机密进行本地开发,但在配置依赖注入服务时,我一直困惑于如何访问这些机密值:

// secrets.json

{
  "apiKey": "1234567890"
}
Run Code Online (Sandbox Code Playgroud)
// Program.cs

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(s =>
    {
        string apiKey = ???;  // how to access user secrets here?
        s.AddScoped<IMyDependency>(sp => new MyDependency(apiKey));
    });
    .Build();
}

host.Run();
Run Code Online (Sandbox Code Playgroud)

Microsoft 提供了有关使用用户机密的指南:

但是这些解决方案都没有提供我所需要的,这是在设置依赖项注入时访问用户秘密值的一种方法。相反,推荐的解决方案使配置值本身注入依赖项,这是我无法使用的。

我尝试过的事情:

dependency-injection asp.net-core azure-functions

1
推荐指数
1
解决办法
1315
查看次数

Azure Functions:无法打开库“ODBC Driver 17 for SQL Server”

我编写了一个 Python 脚本,用于连接到位于 Azure 环境中托管的虚拟机中的 SQL Server。

我已经能够在虚拟机中本地成功连接并运行查询,但是当我部署到 Azure Functions 时,出现以下错误:

('01000', "[01000] [unixODBC][驱动程序管理器]无法打开 lib 'ODBC Driver 17 for SQL Server': 文件未找到 (0) (SQLDriverConnect)")

几天前我成功运行了脚本并连接到数据库,但由于某种原因,它停止工作,现在出现此错误。

import pyodbc


DatabaseServer = 'Server'
DatabaseName = 'databasename'
conn_str = "Driver={ODBC Driver 17 for SQL Server };Server="+str(DatabaseServer)+';Database='+str(DatabaseName)+";'Trusted_Connection=yes;"

try:
    # Connect to the SQL Server
    conn = pyodbc.connect(conn_str)
    cursor = conn.cursor()

    # Execute the query
    cursor.execute("SELECT TOP 10 hmy FROM Table")

    # Fetch and print the results
    rows = cursor.fetchall()
    results_str = ""
    for row in …
Run Code Online (Sandbox Code Playgroud)

python sql-server azure pyodbc azure-functions

1
推荐指数
1
解决办法
2340
查看次数

Azure功能:有没有办法从Azure SDK处理TimerTrigger?

我正在寻找一个简单的调度程序来在我的部署在Azure云中的Java Web应用程序中执行任务.我正在根据我的要求使用TimerTrigger评估Azure函数.在这里,我计划使用回调API URL定义Azure函数,以调用我的应用程序在我的应用程序中执行任务.

我对这种方法有一些疑问.任何人都可以帮助我如果你熟悉Azure功能吗?

1)是否可以在运行时通过API从Java应用程序启动/重新安排/取消Azure TimerTrigger功能?

2)如果是,是否可以将回拨URL传递给定时器触发器?

3)使用Azure功能有任何已知的缺点吗?

谢谢!

azure azure-functions

0
推荐指数
1
解决办法
405
查看次数

服务总线队列触发器,Azure函数多次调用同一消息

我有两个azure函数,一个是http函数,另一个是队列触发函数.在http函数中,我在队列中添加了一个消息,并在队列触发器中处理它.当我在队列触发器中记录消息时,有时它会使用相同的消息多次触发?会是什么原因?

提前致谢

azure azureservicebus azure-servicebus-queues azure-functions

0
推荐指数
1
解决办法
521
查看次数

如何为longrunning azure函数创建启动代码?

我计划创建一个始终运行的函数项目,但根据azure函数响应多个触发器.

我知道这可以通过webjobs来完成,但可以通过功能完成吗?如果是这样,我如何将启动文件挂钩作为longrunning(阻塞)后台任务的入口点?

c# azure azure-webjobs azure-functions

0
推荐指数
1
解决办法
857
查看次数

在Visual Studio 2017中架构和管理Azure功能

如何在Visual Studio中创建多个“功能应用程序”?如果我创建一个新项目并选择“ Azure功能”(等于门户中的Function Apps)。在项目中,可以创建多个“ Azure函数”。发布后,每个人都可以在我的“功能应用程序”下看到。但是,如果我需要多功能应用程序怎么办?我需要在解决方案中为每个项目创建一个新项目吗?如果可以用文件夹和名称空间解决,那就太好了。

c# azure azure-functions

0
推荐指数
1
解决办法
206
查看次数

C#中Azure功能的Application Insight Logging

我们在C#中具有服务总线触发的Azure函数。我想在Application Insight中记录信息(例如调用的函数,结果,异常)。我已将TraceWriter转换为Ilogger以获取登录信息。我要实现的是在控制台(本地)以及Application Insight实例上进行日志记录。什么是实现此目标的完美方法?

    public static class AIFunction
{
    private static string key = TelemetryConfiguration.Active.InstrumentationKey = "************************";

    private static TelemetryClient telemetryClient =
        new TelemetryClient() { InstrumentationKey = key };

    [FunctionName("AIFunction")]
    public static void Run([ServiceBusTrigger("AIFunctionQueue", AccessRights.Manage, Connection = "ServiceBus")]string queueItem, ILogger log)
    {
        telemetryClient.Context.Cloud.RoleName = "AIFunction";
        log.LogInformation($"C# ServiceBus queue trigger function processed message: {queueItem}");
        log.LogInformation($"C# ServiceBus queue trigger function to test Application Insight Logging");
        telemetryClient.TrackEvent("AIFunction TrackEvent");
        telemetryClient.TrackTrace("AIFunction TrackTrace");
    }
}
Run Code Online (Sandbox Code Playgroud)

c# azure azure-application-insights azure-functions azure-functions-runtime

0
推荐指数
1
解决办法
3960
查看次数

如何在blob存储中创建文件夹

我有一个文件,如Parent.zip与解压缩时,会产生这些文件:child1.jpg,child2.txt,child3.pdf.

运行Parent.zip下面的函数时,文件正确解压缩为:

some-container/child1.jpg
some-container/child2.txt
some-container/child3.pdf
Run Code Online (Sandbox Code Playgroud)

如何将文件解压缩到其父文件夹?期望的结果是:

some-container/Parent/child1.jpg
some-container/Parent/child2.txt
some-container/Parent/child3.pdf
Run Code Online (Sandbox Code Playgroud)

如上所示,文件夹Parent已创建.

我用它来创建blob中的文件:

            using (var stream = entry.Open ()) {
                //check for file or folder and update the above blob reference with actual content from stream
                if (entry.Length > 0) {
                    await blob.UploadFromStreamAsync (stream);
                }
            }
Run Code Online (Sandbox Code Playgroud)

这是完整的来源:

[FunctionName ("OnUnzipHttpTriggered")]
public static async Task<IActionResult> Run (
    [HttpTrigger (AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
    ILogger log) {
    log.LogInformation ("C# …
Run Code Online (Sandbox Code Playgroud)

.net c# azure azure-storage-blobs azure-functions

0
推荐指数
1
解决办法
914
查看次数