serverless / serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
MIT License
266 stars 161 forks source link

cosmosDB bindings: Error: Binding direction/name/databaseName/collectionName not supported #507

Open blomm opened 3 years ago

blomm commented 3 years ago

This is a Bug Report

Description

functions:
  sampleQuery:
    handler: src/handlers/sample.query
    events:
      - http: true
        methods:
          - POST
        authLevel: anonymous
      - cosmosDB:
        direction: out
        name: record # name of input parameter in function signature
        databaseName: sampleDB
        collectionName: sampleCollection
        connectionStringSetting: COSMOS_DB_CONNECTION # name of appsetting with the connection string
        createIfNotExists: true # A boolean value to indicate whether the collection is created when it doesn't exist.

Similar or dependent issues:

image

Additional Data

Your Environment Information --------------------------- Operating System: darwin Node Version: 10.16.0 Framework Version: 2.8.0 Plugin Version: 4.1.1 SDK Version: 2.3.2 Components Version: 3.2.7

blomm commented 3 years ago

It's essentially not liking any bindings under cosmosDB, am I missing a needed plugin? I've got serverless-azure-functions installed and I mention it in the plugins section of the serverless.yml file

blomm commented 3 years ago

I added some extra logging:

if (index < 0) {
                                console.log("acceptable binding types: " + JSON.stringify(bindingTypes))
                                throw new Error("Binding  " + bindingType + " not supported");
                            }

what it printed out was this: ["timerTrigger","eventHubTrigger","eventHub","queue","queueTrigger","blob","blob","blobTrigger","apiHubFile","apiHubFile","apiHubFileTrigger","apiHubTable","apiHubTable","httpTrigger","http","serviceBusTrigger","serviceBus","manualTrigger","table","table","cosmosDB","cosmosDB","cosmosDBTrigger","mobileTable","mobileTable","notificationHub","sendGrid","twilioSms","bot","bot"]

blomm commented 3 years ago

when I don't include any properties under cosmosDB, it says: Error: Required property connectionStringSetting is missing for binding:cosmosDB When I add connectionStringSetting (or anything under cosmosDB) it says: Error: Binding connectionStringSetting not supported

jis260 commented 3 years ago

I have been having similar issues with the sendGrid binding. I also just tried the cosmosDB binding and I found that I need to use "x-azure-settings:" like:

- cosmosDB:
  x-azure-settings:
    direction: out
    name: record # name of input parameter in function signature
    databaseName: databaseName
    collectionName: collectionName
    connectionStringSetting: COSMOS_DB_CONNECTION # name of appsetting with the connection string
    createIfNotExists: false # A boolean value to indicate whether the collection is created when it doesn't exist.

If I look at the Azure function "function.json" it has:

{
      "type": "cosmosDB",
      "direction": "out",
      "name": "record",
      "databaseName": "databaseName",
      "collectionName": "collectionName",
      "createIfNotExists": false,
      "connectionStringSetting": "COSMOS_DB_CONNECTION"
 } 

I also found that if you don't have another output binding specified then the "name" property gets ignored and is set to "$return". So I set it like:

    events:
      - http: true
        methods:
          - POST
        authLevel: function
      - http:
        x-azure-settings:
          direction: out
      - cosmosDB:
        x-azure-settings:
          direction: out
          name: doc
          databaseName: databaseName
          collectionName: collectionName
          connectionStringSetting: COSMOS_DB_CONNECTION # name of appsetting with the connection string
          createIfNotExists: false # A boolean value to indicate whether the collection is created when it doesn't exist.  

In the function.json it displays as:

   {
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "authLevel": "function",
      "methods": [
        "POST"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    },
    {
      "type": "cosmosDB",
      "direction": "out",
      "name": "doc",
      "databaseName": "databaseName",
      "collectionName": "collectionName",
      "createIfNotExists": false,
      "connectionStringSetting": "COSMOS_DB_CONNECTION"
    }

For sendGrid this does not seem to work. Unfortunately, I have been unable to get the output binding working correctly. Whenever, the cosmosDB binding is included and I try to call the Azure function it gives a 404 not found error.

jis260 commented 3 years ago

I should add that: Framework Core: 1.73.0 Plugin: 3.6.13 SDK: 2.3.1 Components: 2.30.15

jis260 commented 3 years ago

If I try the same approach with: Operating System: linux Node Version: 12.18.1 Framework Version: 2.9.0 (standalone) Plugin Version: 4.1.1 SDK Version: 2.3.2 Components Version: 3.2.7

Error: Binding not supported If I remove x-azure-settings: then I get this error: Error: Required property createIfNotExists is missing for binding:cosmosDB

blomm commented 3 years ago

For me, it doesn't matter what binding I put under cosmosdb, I get "Error: Binding not supported"

ianrandell-sh commented 3 years ago

try setting - cosmosDB:

to - cosmosDB: true

I've had similar issue with serviceBus binding and been debugging the transpiled js For ref my yaml had to look like this:

functions:
  myFunc:
    handler: myFunc.Run
    events:
      - serviceBus: true  #<--- NEED TRUE HERE
        name: message
        queueName: myQueue
        accessRights: manage
        connection: SERVICE_BUS_CONNECTION

The x-azure-settings is irrelevant for the latest version of the plugin.

blomm commented 3 years ago

Interestingly, adding "true" means that it only complains about one property, "connectionStringSetting", rather than complaining about the first one on the list. Error: connectionStringSetting not supported and when I remove it: Error: Required property connectionStringSetting is missing for binding:cosmosDB

I was only trying with the x-azure-settings because I saw in the code that although it was legacy it was still supported.

ianrandell-sh commented 3 years ago

Possibly "connectionStringSetting" should be "connection"

Edit: looks like it should be "connectionStringSetting"

image

ngjm commented 3 years ago

try setting - cosmosDB:

to - cosmosDB: true

I've had similar issue with serviceBus binding and been debugging the transpiled js For ref my yaml had to look like this:

functions:
  myFunc:
    handler: myFunc.Run
    events:
      - serviceBus: true  #<--- NEED TRUE HERE
        name: message
        queueName: myQueue
        accessRights: manage
        connection: SERVICE_BUS_CONNECTION

The x-azure-settings is irrelevant for the latest version of the plugin.

@ianrandell-sh Thank you for this. This fixed an issue the issue I was seeing for the eventHub trigger.