serverless-azure-functions
serverless-azure-functions copied to clipboard
eventHub trigger not working on azure portal
This is a Bug Report
Description
- What went wrong? I successfully deploy my serverless functions to Azure, setting eventHub as binding. While I visit the function page on azure an error appears and the function does not work:
Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.myfunc'. Microsoft.Azure.WebJobs.EventHubs: Value cannot be null. Parameter name: receiverConnectionString.
- What did you expect should have happened? The function to work correctly
- What was the config you used? serverless.yml
myfunc:
handler: src/entrypoint.myfunc
events:
- eventHub:
x-azure-settings:
name: items # Specifies which name it's available on `context`
eventHubName: myfunc-events # Specifies the Name of the Event Hub
consumerGroup: myfuncchannel # Specifies the consumerGroup to listen with
connection: ${opt:eh} # App Setting/environment variable which contains Event Hubs Namespace Connection String
- What stacktrace or error message from your provider did you see? function.json
{
"disabled": false,
"bindings": [
{
"type": "eventHubTrigger",
"direction": "in",
"name": "items",
"eventHubName": "myfunc-events",
"consumerGroup": "myfuncchannel",
"connection": "Endpoint={myurl}"
}
],
"entryPoint": "myfunc",
"scriptFile": "../src/entrypoint.js"
}
error
Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.myfunc'. Microsoft.Azure.WebJobs.EventHubs: Value cannot be null. Parameter name: receiverConnectionString.
Similar or dependent issues:
- #352
Additional Data
- Serverless Framework Version you're using: 1.54.0
- Serverless CLI Version you're using: 1.2.3
- Serverless Azure Plugin Version you're using: 1.0.2
- Operating System: darwin
@leopuleo
- can you share your
src/entrypoint.js
? - When you say "visit the function page on azure", do you mean accessing the function url?
- 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)?
- Base on your
Hi @mydiemho,
- 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 });
}
};
- 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).
Also, I noticed inside the "Integrate" tab the "EventHub connection" input is empty
- 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!
-
Where did you set the connection string inside the
serverless.yml
file?- Replace the
connection: ${opt:eh}
withconnection: 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.
- Replace the
-
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
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.
But the situation does not change:
- I still have the red banner with error.
- 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
@leopuleo did you solve this problem? I am having the same.
Unfortunately, I don't know...I moved away from serverless framework.
I'm deploying my functions using azure-cli
Yesterday, I got to do. Follow an example:
example: handler: src/app/example.handler events: - eventHub: true x-azure-settings: name: eventHubMessages eventHubName: example consumerGroup: $Default connection: EVENT_HUB_CONNECTION_STRING cardinality: many