Azure / azure-functions-vs-build-sdk

MSBuild task for Azure Functions
MIT License
96 stars 62 forks source link

function input Binding with cosmosDb not working #605

Closed badrdouah closed 1 year ago

badrdouah commented 1 year ago

Hi,

I've been trying to bind a cosmosdb input with an azure function with no luck, i'm developing the function locally using .net , when i deploy it it shows the following schema in the integration blade

Screen Shot 2023-01-13 at 1 04 55 AM

here is my .net function


using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

//         
namespace cosmosDBFunc
{
    public static class cosmosDBFunc
    {
        [FunctionName("cosmosDBFunc")]
        public static IActionResult Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,

        [CosmosDB("MY DB NAME", "MY CONTAINER NAME", Connection = "MY CONNECTION STR ENV VARIABLE NAME")] dynamic myContent, ILogger log)
        {

            var json = JsonConvert.SerializeObject(myContent);
            return new OkObjectResult(json);
        } 
    }
}

My function.json

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-4.1.3",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "methods": [
        "get"
      ],
      "authLevel": "function",
      "name": "req"
    },
    {
      "type": "cosmosDB",
      "connection": "MY CONNECTION STR ENV VARIABLE NAME",
      "databaseName": "MY DB NAME",
      "containerName": "MY CONTAINER NAME",
      "createIfNotExists": false,
      "name": "myContent"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/cosmosDBFunc.dll",
  "entryPoint": "cosmosDBFunc.cosmosDBFunc.Run"
}