Azure Event Grid binding spec

To setup Azure Event Grid binding create a component of type . See this guide on how to create and apply a binding configuration.

See for Azure Event Grid documentation.

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described .

Scope is the identifier of the resource to which the event subscription needs to be created or updated. The scope can be a subscription, or a resource group, or a top level resource belonging to a resource provider namespace, or an Event Grid topic. For example:

  • '/subscriptions/{subscriptionId}/' for a subscription
  • '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a resource group
  • '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}' for a resource
  • '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}' for an Event Grid topic

This component supports output binding with the following operations:

  • create

Event Grid Binding creates an event subscription when Dapr initializes. Your Service Principal needs to have the RBAC permissions to enable this.

  1. # First ensure that Azure Resource Manager provider is registered for Event Grid
  2. az provider register --namespace Microsoft.EventGrid
  3. # Give the SP needed permissions so that it can create event subscriptions to Event Grid
  4. az role assignment create --assignee <clientId> --role "EventGrid EventSubscription Contributor" --scopes <scope>

Make sure to also to add quotes around the [HandshakePort] in your Event Grid binding component because Kubernetes expects string values from the config.

  • Run locally using custom port 9000 for handshakes
  1. # Using random port 9000 as an example
  2. ngrok http -host-header=localhost 9000
  • Configure the ngrok’s HTTPS endpoint and custom port to input binding metadata
  • Run Dapr

Azure Event Grid requires a valid HTTPS endpoint for custom webhooks. Self signed certificates won’t do. In order to enable traffic from public internet to your app’s Dapr sidecar you need an ingress controller enabled with Dapr. There’s a good article on this topic: .

To get started, first create dapr-annotations.yaml for Dapr annotations

  1. controller:
  2. podAnnotations:
  3. dapr.io/enabled: "true"
  4. dapr.io/app-id: "nginx-ingress"
  5. dapr.io/app-port: "80"
  1. helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
  2. helm repo update
  3. helm install nginx-ingress ingress-nginx/ingress-nginx -f ./dapr-annotations.yaml -n default
  4. # Get the public IP for the ingress controller
  5. kubectl get svc -l component=controller -o jsonpath='Public IP is: {.items[0].status.loadBalancer.ingress[0].ip}{"\n"}'

If deploying to Azure Kubernetes Service, you can follow the official MS documentation for rest of the steps

  • Add an A record to your DNS zone
  • Install cert-manager
  • Create a CA cluster issuer

Final step for enabling communication between Event Grid and Dapr is to define http and custom port to your app’s service and an in Kubernetes. This example uses .NET Core web api and Dapr default ports and custom port 9000 for handshakes.

Deploy binding and app (including ingress) to Kubernetes

  1. # Deploy Dapr components
  2. kubectl apply -f eventgrid.yaml
  3. kubectl apply -f dotnetwebapi.yaml

Troubleshooting possible issues with Nginx controller

After initial deployment the “Daprized” Nginx controller can malfunction. To check logs and fix issue (if it exists) follow these steps.

  1. $ kubectl get pods -l app=nginx-ingress
  2. NAME READY STATUS RESTARTS AGE
  3. nginx-nginx-ingress-controller-649df94867-fp6mg 2/2 Running 0 51m
  4. nginx-nginx-ingress-default-backend-6d96c457f6-4nbj5 1/1 Running 0 55m
  5. $ kubectl logs nginx-nginx-ingress-controller-649df94867-fp6mg nginx-ingress-controller
  6. # If you see 503s logged from calls to webhook endpoint '/api/events' restart the pod
  7. # .."OPTIONS /api/events HTTP/1.1" 503..
  8. $ kubectl delete pod nginx-nginx-ingress-controller-649df94867-fp6mg
  9. # Check the logs again - it should start returning 200