Load data from cosmos db to Event hub using Azure Function at Azure Portal

One way to load data from Cosmos DB to Event hub is to use Azure Function. But although there is many coding samples out there to create such Azure Function. If you are like me do not have much application development experience, reading those code samples is bit channenging. Luckly, Azure Portal made is so easy.

  • Navigate to your Cosmos DB on Azure Portal, on the left pannel, you can find a choice under Settings called ‘Add Azure Function’

CosmosDB Azure Function 1

  • Fill the form popped up after you clicked on ‘Add Azure Function’ and choose the Function Language as C#. Then click ‘Save’
    • CosmosDB Azure Function 2

 

  • The portal will automaticly navigate to the Azure Function Apps page. and you will find the newly created Azure Function there. The next steps for us is to add the data target. In this case, it is Event hub. To add the Azure Function output target,
    • Click on ‘Integrate’
    • Click on the ‘Output’ New Output in the center form
    • Then choose ‘Azure Event Hub’ from the output choices
    • Save
      CosmosDB Azure Function 3
  • After you hit save, you will see the output form. change the Event Parameter Name field to be ‘$return’. And make sure the ‘Use Function Return Value’ is checked before ‘Save’
    CosmosDB Azure Function 4
  • The next step is to update the Azure Function run.csx code to create the data integration code.
    • Click on the FunctionName itself and the run.csx editing page will show up.
    • Then change the current code into this code
    • And click on ‘Save and Run’
    • Please note where I highlighted in yellow, depends on which run time version of Azure Functions App you have. the reference file can be either #r “Microsoft.Azure.Documents.Client” or #r “Microsoft.Azure.DocumentDB.Core”. So interchange those two if you run into error.
      • CosmosDB Azure Function 5
  • Now, your azure function is up running and capturing the changes and sending the changed files to event hub.

 

Thanks,

Your friend, Annie

One thought on “Load data from cosmos db to Event hub using Azure Function at Azure Portal

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: