Provisioning an Event Grid Topic

Preview

Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in

Provisioning an Event Grid Topic

This guide shows you how to provision an Event Grid Topic against Locally. As with the other guides we're going to use the Azure CLI, but the same resources can be provisioned with HashiCorp Terraform, Pulumi or Bicep too.

Before you start

Plugin required

This requires the Microsoft.EventGrid plugin, which you can install with:

$ locally plugin install --name Microsoft.EventGrid

1. Start Locally

Firstly, we need to launch Locally which we can do from a terminal by running:

$ locally build

Once Locally has started, the Locally Dashboard will open automatically:

Screenshot of the Locally Dashboard

2. Create a Resource Group

Next we can create the Resource Group:

$ locally run az group create -n sample-resources -l berlin

There's two things to note here:

  1. The Azure CLI supports Automatic Configuration, meaning that it can automatically be configured to work against Locally just by prefixing commands with locally run.
  2. Locally intentionally uses a different set of locations to Azure as a safety precaution, so that you can be confident you're deploying against Locally rather than regular Azure. You can also configure Locally to use the Azure locations too, but you'll want to be extra sure that you're prefixing commands with locally run when you do.

3. Create the Event Grid Topic

With the Resource Group in place, we can create the Event Grid Topic - the endpoint publishers send events to:

$ locally run az eventgrid topic create -g sample-resources -n sample-topic -l berlin
{
  "endpoint": "https://sample-topic-berlin.eventgrid.locally:5662/api/events",
  "name": "sample-topic",
  "state": "Succeeded"
}

That eventgrid.locally hostname is served by Locally's own DNS server and points at the Event Grid Emulator running on your machine.

4. Get a publishing key

Publishing to a topic needs a key as well as the endpoint:

$ locally run az eventgrid topic key list -g sample-resources -n sample-topic --query key1 -o tsv

Together with the endpoint above, that's everything an SDK needs to publish events.

We can list the topics in the Resource Group:

$ locally run az eventgrid topic list -g sample-resources --query "[].{Name:name, Endpoint:endpoint, State:provisioningState}" -o table

Note

A topic on its own accepts events but delivers them nowhere. Event subscriptions are what route events to a handler, and are worth adding once you have something to deliver to.

We can see the Event Grid Topic in the Locally Dashboard too:

Screenshot of the Event Grid Topic in the Locally Dashboard

5. Tidy up

Finally, we can tidy up. To remove the Resource Group and everything within it:

$ locally run az group delete -n sample-resources --yes

There's nothing billable to clean up, since everything ran on your machine, but it's still worth checking your teardown scripts work here before you run them against Azure.

Doing this with other tooling

Whilst this guide used the Azure CLI, Event Grid works the same way through any of the tooling that Locally supports - a Microsoft.EventGrid/topics resource in HashiCorp Terraform or OpenTofu, Pulumi, Bicep or an ARM Template all provision against Locally in the same way, with only the location changed.

Next steps

The Event Grid Emulator lets you publish events from the browser and see each delivery. To handle events in code, see Function App.

Should you encounter any issues, please take a look at the troubleshooting section.

Preview

Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in

A local cloud for you and your AI agents.

Your Azure infrastructure, running on your machine. Deploy in seconds, break things freely, and ship to Azure when you're ready.