Created
December 3, 2019 12:58
-
-
Save ianphil/cd8de3b3d80fbfa7683c7878ac97d249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
resourcegroup="ipeventgrid-rg" | |
subscriptionid="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" | |
sitename="ipeventgrid-ws" | |
topicname="iptopic" | |
# Create resource group | |
az group create --name "$resourcegroup" --location eastus2 | |
# Deploy EventGrid Viewer website | |
az group deployment create \ | |
--resource-group "$resourcegroup" \ | |
--template-uri "https://raw.githubusercontent.com/Azure-Samples/azure-event-grid-viewer/master/azuredeploy.json" \ | |
--parameters "siteName=$sitename hostingPlanName=viewerhost" | |
# Register EventGrid provider (if needed) | |
az provider register --namespace Microsoft.EventGrid | |
az provider show --namespace Microsoft.EventGrid --query "registrationState" | |
# Create EventGrid topic | |
az eventgrid topic create --name "$topicname" --location eastus2 --resource-group "$resourcegroup" | |
# Subscribe the Viewer to the EventGrid topic | |
endpoint="https://$sitename.azurewebsites.net/api/updates" | |
az eventgrid event-subscription create \ | |
--source-resource-id "/subscriptions/$subscriptionid/resourceGroups/$resourcegroup/providers/Microsoft.EventGrid/topics/$topicname" \ | |
--name demoViewerSub \ | |
--endpoint "$endpoint" | |
# Capture EventGrid topic endpoint and auth key | |
eventgridendpoint=$(az eventgrid topic show --name "$topicname" --resource-group "$resourcegroup" --query "endpoint" --output tsv) | |
eventgridkey=$(az eventgrid topic key list --name "$topicname" --resource-group "$resourcegroup" --query "key1" --output tsv) | |
# Create and send event | |
event='[ {"id": "'"$RANDOM"'", "eventType": "recordInserted", "subject": "myapp/vehicles/motorcycles", "eventTime": "'`date +%Y-%m-%dT%H:%M:%S%z`'", "data":{ "make": "Ducati", "model": "Monster"},"dataVersion": "1.0"} ]' | |
curl -X POST -H "aeg-sas-key: $eventgridkey" -d "$event" "$eventgridendpoint" | |
# Clean up | |
az group delete --name "$resourcegroup" --yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment