部署后,带有CosmosDb输入的HTTPTrigger Azure功能不起作用

时间:2020-06-02 22:24:18

标签: azure azure-functions azure-cosmosdb

我创建了下面的HttpTrigger函数,该函数将CosmosDb项目作为输入。在本地运行时,此代码可以完美运行。在本地成功运行后,我使用Visual Studio Code创建功能并部署到Azure。但这在Azure上不起作用,它不会给出错误或者似乎没有任何响应。

public static class HttpTriggerWithCosmosDb
{
    [FunctionName("HttpTriggerWithCosmosDb")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "HttpTriggerWithCosmosDb/{id}")] HttpRequest req,
        [CosmosDB(
            databaseName : "func-io-learn-db",
            collectionName : "Bookmarks",
            ConnectionStringSetting = "CosmosDBConnection",
            Id = "{id}",
            PartitionKey = "{id}"
        )] BookMarkItem item,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string name = item.Url;

        Console.Write( item.Id);

        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        name = name ?? data?.name;

        string responseMessage = string.IsNullOrEmpty(name)
            ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
            : $"Hello, {name}. This HTTP triggered function executed successfully.";

        return new OkObjectResult(responseMessage);
    }
}

发布时,在输出中,我看到以下消息:

HttpTriggerCSharp1: https://nps-func.azurewebsites.net/api/HttpTriggerCSharp1
TestMessage:https://nps-func.azurewebsites.net/api/TestMessage 下午5:33:02 nps-func:警告:某些http触发网址不能为 显示在输出窗口中,因为它们需要身份验证 令牌。

没有显示此功能。 enter image description here

更新: 完整代码可在Git

上找到

1 个答案:

答案 0 :(得分:0)

我遇到了问题,这里发生了什么。在发布功能之前,我必须使用 Azure Function:Add New Settings ... 命令手动将CosmosDBConnection添加到Azure。

我是新手,我不知道这是需要添加app_settings的方式。