Open leopuleo opened 5 years ago
@leopuleo
src/entrypoint.js
?serverless.yml
snippet, you're trying to pass in the connection string from the command line. 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).
Also, I noticed inside the "Integrate" tab the "EventHub connection" input is empty
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!
Where did you set the connection string inside the serverless.yml
file?
connection: ${opt:eh}
with connection: AZURE_EH_CONNECTION_STRING
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.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:
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:
This is a Bug Report
Description
What did you expect should have happened? The function to work correctly
What was the config you used? serverless.yml
What stacktrace or error message from your provider did you see? function.json
error
Similar or dependent issues:
352
Additional Data