serverless / serverless-azure-functions

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

eventHub trigger not working on azure portal #361

Open leopuleo opened 5 years ago

leopuleo commented 5 years ago

This is a Bug Report

Description

Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.myfunc'. Microsoft.Azure.WebJobs.EventHubs: Value cannot be null. Parameter name: receiverConnectionString.

Additional Data

mydiemho commented 5 years ago

@leopuleo

  1. can you share your src/entrypoint.js?
  2. When you say "visit the function page on azure", do you mean accessing the function url?
  3. The error is saying that you did not provide the connection string for your EventHub service.
    • Base on your serverless.yml snippet, you're trying to pass in the connection string from the command line.
    • How are you deploying the app? Can you provide the full command used (masking any secrets)?
leopuleo commented 5 years ago

Hi @mydiemho,

1) can you share your src/entrypoint.js?

/src/entrypoint.js

import { myfuncChannel } from "./channels/myfunc";

export function myfunc(context, items) {
    return myfuncChannel(context, items);
}

/channels/myfunc.js

export const myfuncChannel = async (context, items) => {
    try {
        const messages = Array.isArray(items) ? items : [items];
        ...
        context.done();
    } catch (error) {
        context.done(error.message, { status: 500 });
    }
};

2) When you say "visit the function page on azure", do you mean accessing the function url?

No, the actual page on Azure Portal (see screenshot attached).

Screenshot 2019-10-17 at 09 25 25

Also, I noticed inside the "Integrate" tab the "EventHub connection" input is empty

Screenshot 2019-10-17 at 09 25 51

3) The error is saying that you did not provide the connection string for your EventHub service.

serverless.yml

service: channels

provider:
    name: azure
    runtime: nodejs10.x
    region: ${opt:region, 'westeurope'}
    stage: ${opt:stage, 'dev'}
    prefix: ${opt:prefix, 'ncs'}
    environment:
        AZURE_EH_CONNECTION_STRING: ${opt:eh}
        BRANCH_NAME: ${opt:stage}

plugins:
    - serverless-azure-functions
    - serverless-webpack

custom:
    webpack:
        webpackConfig: "webpack.config.js" # Name of webpack configuration file
        includeModules: false # Node modules configuration for packaging
        packager: "npm" # Packager that will be used to package your external modules
        excludeFiles: "tests/**/**/*.js" # Provide a glob for files to ignore

functions:
    myfunc:
        handler: src/entrypoint.myfunc
        events:
            - eventHub:
              x-azure-settings:
                  name: items
                  eventHubName: myfunc-events
                  consumerGroup: myfuncchannel 
                  connection: ${opt:eh} 

serverless cmd

serverless deploy --region westeurope --stage dev --eh "Endpoint=sb://{myEHconnectionString}" --verbose

I also tried to set the full connection string inside the `serverless.yml, with no success. Thank you!

mydiemho commented 5 years ago
  1. Where did you set the connection string inside the serverless.yml file?

    • Replace the connection: ${opt:eh} with connection: AZURE_EH_CONNECTION_STRING
    • When you set AZURE_EH_CONNECTION_STRING in the environment section, this create an app setting with that key and the assigned value (whatever you gave ${opt:eh}). Thus, you want to reference that app setting in your bindings.
  2. This is eventhub trigger event, which means items is only available when it's trigger by an event being added to the eventhub. When you "trigger" it from the portal, it's doing an http trigger, and items is null at this point.

You'll have to send the events separately https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-node-get-started-send#send-events

leopuleo commented 5 years ago

Where did you set the connection string inside the serverless.yml file?

Inside the deploy command:

serverless deploy --region westeurope --stage dev --eh "Endpoint=sb://{myEHconnectionString}" --verbose

Replace the connection: ${opt:eh} with connection: AZURE_EH_CONNECTION_STRING When you set AZURE_EH_CONNECTION_STRING in the environment section, this create an app setting with that key and the assigned value (whatever you gave ${opt:eh}). Thus, you want to reference that app setting in your bindings.

Done! The script saves a new AZURE_EH_CONNECTION_STRING environment variable. Screenshot 2019-10-18 at 09 45 00

But the situation does not change:

  1. I still have the red banner with error.
  2. The "Event Hub Connection" string is still empty.

This is eventhub trigger event, which means items is only available when it's trigger by an event being added to the eventhub. When you "trigger" it from the portal, it's doing an http trigger, and items is null at this point.

I got the error while a visit the function page, I'm not triggering the function via the azure portal. Sending event to the connected EH, it's not consumed by the receiver function

williampenna commented 3 years ago

@leopuleo did you solve this problem? I am having the same.

leopuleo commented 3 years ago

Unfortunately, I don't know...I moved away from serverless framework. I'm deploying my functions using azure-cli

williampenna commented 3 years ago

Yesterday, I got to do. Follow an example:

`example: handler: src/app/example.handler events: