serverless / serverless-azure-functions

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

ServiceBusTrigger values in function.json not as defined in yml #508

Open ianrandell-sh opened 3 years ago

ianrandell-sh commented 3 years ago

This is a Bug Report

Description

serverless.yml:

service: oscarsinkfunc-app

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: '2'

provider:
  name: azure
  region: West Europe
  runtime: dotnet3.1
  prefix: "ianr"
  subscriptionId: ...redacted...
  stage: dev

  environment: 
    SERVICE_BUS_CONNECTION: '...redacted...'

plugins: 
  - serverless-azure-functions

functions:
  oscarsinkfunc:
    handler: src/handlers/oscarsinkfuncclass.main
    events:
      - serviceBus: true
        name: message 
        queueName: myqueue
        accessRights: listen
        connection: SERVICE_BUS_CONNECTION

c#:

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System;

namespace myNamespace
{
    public static class oscarsinkfuncclass
    {
        [FunctionName("oscarsinkfuncname")]
        public static void Run(
            [ServiceBusTrigger("blahqueue", Connection = "blahconnection")]
            string message,
            ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function {nameof(oscarsinkfuncclass)} processed message: {message ?? "(null)"}");
        }

Resulting function.json (taken from the azure portal via func -> code+test):

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-3.0.9",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "connection": "blahconnection",
      "queueName": "blahqueue",
      "isSessionsEnabled": false,
      "name": "message"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/OscarSinkFunctionApp.dll",
  "entryPoint": "myNamespace.oscarsinkfuncclass.Run"
}

Similar or dependent issues:

Additional Data

ianrandell-sh commented 3 years ago

additionally, setting the values to null in c# does not work

[ServiceBusTrigger(null, Connection = null)]

the function.json (from the zip in .serverless) is missing the values entirely:

"bindings": [
    {
      "type": "serviceBusTrigger",
      "isSessionsEnabled": false,
      "name": "message"
    }
  ],
ianrandell-sh commented 3 years ago

FYI the workaround I'm using is to use the %% syntax for the c# queue prop:

[ServiceBusTrigger("%SERVICE_BUS_QUEUE_NAME%", Connection = "SERVICE_BUS_CONNECTION")]

and then define the queue name as env var in the serverless.yml:

  environment:
    SERVICE_BUS_CONNECTION: '...redacted...'
    SERVICE_BUS_QUEUE_NAME: '...redacted...'