如何使用 Azure 资源管理器 API 创建 Azure Function App v4

问题描述 投票:0回答:1

考虑以下适用于

v4
之前的函数应用程序的代码:

var bindingsConfig = new
{
    bindings = new object[]
        {
            new
            {
                AuthLevel = "function",
                Type = "httpTrigger",
                Direction = "in",
                Name = "request",
                Methods = new[] {"post"}
            },
            new
            {
                Type = "http",
                Direction = "out",
                Name = "$return"
            }
        }
};

app = await myResourceGroup.GetWebSites().GetAsync("my-app-name", ct);
var func = await app.GetSiteFunctions().CreateOrUpdateAsync(WaitUntil.Completed, "my-func-name", new FunctionEnvelopeData
{
    Config = BinaryData.FromObjectAsJson(config)
}, ct);

现在根据 this doc

function.json
不再在
v4
编程模型中使用。我的问题是 - 这是否意味着我不应该将
bindingsConfig
传递到
CreateOrUpdateAsync()
?当我尝试时,我收到以下错误:

Azure.RequestFailedException: 'Error creating function. <my-func-name> is not a valid function name
Status: 400 (Bad Request)
ErrorCode: BadRequest

一般来说,我应该如何调用

CreateOrUpdateAsync()
来创建
v4
类型的函数?

azure azure-functions azure-resource-manager
1个回答
0
投票

对于那些对解析感兴趣的人来说,事实证明,对

app.GetSiteFunctions().CreateOrUpdateAsync()
的调用永远不应该用于创建函数 v4。此调用会导致创建
function.json
的 v3 样式,这与 v4 编程模型发生冲突(v3 和 v4 编程模型不应在一个应用程序中混合使用)。

如果缺少

npm install
文件夹(在 Kudu UI 中),请确保调用
node_modules
也很重要。

© www.soinside.com 2019 - 2024. All rights reserved.