Send Auth0 events to Azure Blob Storage
This article shows you how to send Auth0 events to Azure Blob Storage via Azure Event Grid by using Azure Functions.
Prerequisites
- Create an Azure Event Grid stream on Auth0.
- Create a Azure Blob Storage resource
- Get connection string to Azure Storage account. Make sure you select the Copy button to copy connection string to the clipboard.
Create an Azure function
Create an Azure function by following instructions from the Create a local project section of Quickstart: Create a JavaScript function in Azure using Visual Studio Code.
Select Azure Event Grid trigger for the function template instead of HTTP trigger as mentioned in the quickstart.
Continue to follow the steps, but use the following index.js and function.json files.
Important
Update the package.json to include
@azure/storage-blob
as a dependency.function.json
{ "bindings": [ { "type": "eventGridTrigger", "name": "eventGridEvent", "direction": "in" }, { "type": "blob", "name": "outputBlob", "path": "events/{rand-guid}.json", "connection": "OUTPUT_STORAGE_ACCOUNT", "direction": "out" } ] }
index.js
// Event Grid always sends an array of data and may send more // than one event in the array. The runtime invokes this function // once for each array element, so we are always dealing with one. // See: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid-trigger?tabs= module.exports = async function (context, eventGridEvent) { context.log(JSON.stringify(context.bindings)); context.log(JSON.stringify(context.bindingData)); context.bindings.outputBlob = JSON.stringify(eventGridEvent); };
Create an Azure function app using instructions from Quick function app create.
Deploy your function to the function app on Azure using instructions from Deploy project files.
Configure Azure function to use your blob storage
- Configure your Azure function to use your storage account.
- Select Configuration under Settings on the left menu.
- On the Application settings page, select + New connection string on the command bar.
- Set Name to AzureWebJobsOUTPUT_STORAGE_ACCOUNT.
- Set Value to the connection string to the storage account that you copied to the clipboard in the previous step.
- Select OK.
Create event subscription for partner topic using function
In the Azure portal, navigate to the Event Grid partner topic created by your Auth0 log stream.
On the Create Event Subscription page, follow these steps:
Enter a name for the event subscription.
For Endpoint type, select Azure Function.
Click Select an endpoint to specify details about the function.
On the Select Azure Function page, follow these steps.
- Select the Azure subscription that contains the function.
- Select the resource group that contains the function.
- Select your function app.
- Select your Azure function.
- Then, select Confirm Selection.
Now, back on the Create Event Subscription page, select Create to create the event subscription.
After the event subscription is created successfully, you see the event subscription in the bottom pane of the Event Grid Partner Topic - Overview page.
Select the link to your Azure function at the bottom of the page.
On the Azure Function page, select Monitor and confirm data is successfully being sent. You may need to trigger logs from Auth0.
Verify that logs are stored in the storage account
Locate your storage account in the Azure portal.
Select Containers under Data Storage on the left menu.
Confirm that you see a container named events.
Select the container and verify that your Auth0 logs are being stored.
Note
You can use steps in the article to handle events from other event sources too. For a generic example of sending Event Grid events to Azure Blob Storage or Azure Monitor Application Insights, see this example on GitHub.
Next steps
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for