Integration between Event Hubs and Azure Virtual Networks creates a secure messaging layer that can be accessed from other services within the network. Azure Functions can be similarly integrated with services inside virtual networks, enabling creation of workloads that execute on message ingestion, through input bindings.
This project framework provides the following features:
- An Azure Event Hub used to ingest messages.
- A Function App with an Event Hub triggered Azure Function.
- An Azure Key Vault instance used to securely store all secret values.
- An Azure Virtual Network, Private Endpoints, and network access controls that restrict access to the Event Hub, Storage Account, and Key Vault.
- All components are deployable via Bicep or Terraform.
- Azure CLI (2.42.0)
- Azure Functions Core Tools
- .NET
- Bicep or Terraform
The project can be deployed using either Bicep or Terraform.
- Create a new Azure resource group to deploy the Bicep template to, passing in a location and name -
az group create --location <LOCATION> --name <RESOURCE_GROUP_NAME>
- The azuredeploy.parameters.json file contains the necessary variables to deploy the Bicep project. Update the file with appropriate values. Descriptions for each parameter can be found in the main.bicep file.
- Optionally, verify what Bicep will deploy, passing in the name of the resource group created earlier and the necessary parameters for the Bicep template -
az deployment group what-if --resource-group <RESOURCE_GROUP_NAME> --template-file .\main.bicep --parameters .\azuredeploy.parameters.json
- Deploy the template, passing in the name of the resource group created earlier and the necessary parameters for the Bicep template -
az deployment group create --resource-group <RESOURCE_GROUP_NAME> --template-file .\main.bicep --parameters .\azuredeploy.parameters.json
- The terraform.tfvars file contains the necessary variables to apply the Terraform configuration. Update the file with appropriate values. Descriptions for each variable can be found in the variables.tf file.
- Initialize Terraform -
terraform init
- Optionally, verify what Terraform will deploy -
terraform plan
- Deploy the configuration -
terraform apply
The project provides sample Azure Functions code to verify that the solution is working correctly. It contains an Event Hub triggered Azure Function used to process incoming messages and a second, disabled, timer triggered Azure Function that sends messages to the Event Hub using output bindings and is used to test that the processor is operating properly.
- Navigate to the ./src/eventhub-trigger directory.
- Deploy the code to the function app provisioned by Bicep or Terraform -
func azure functionapp publish <FUNCTION_APP_NAME> --dotnet
- Navigate to the Azure Portal and find the Function App that was provisioned.
- Open the Configuration blade.
- Find the
AzureWebJobs.Tester.Disabled
application setting and edit the value tofalse
. - Save the changes.
- Find the Application Insights resource that was provisioned.
- Open the Logs blade.
- Query for the results from the
requests
table. - Observe the successful
EventHubProcessor
runs.
- Tutorial: Integrate Azure Functions with an Azure virtual network by using private endpoints
- Integrate your app with an Azure virtual network
- Azure Functions networking options
- Network security for Azure Event Hubs
- Configure Azure Storage firewalls and virtual networks
- Configure Azure Key Vault firewalls and virtual networks
- Analyze Azure Functions telemetry in Application Insights