-
Notifications
You must be signed in to change notification settings - Fork 10
/
Route_storage_events_web_endpoint.ps1
68 lines (51 loc) · 2.24 KB
/
Route_storage_events_web_endpoint.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Set-Location c:\
Clear-Host
Install-Module -Name Az -Force -AllowClobber -Verbose
#Basic variables
$prefix = "tw"
$location = "westeurope"
$id = Get-Random -Minimum 1000 -Maximum 9999
#Log into Azure
Connect-AzAccount
#Select the correct subscription
Get-AzSubscription -SubscriptionName "MSDN Platforms" | Select-AzSubscription
#Azure Event Grid is an eventing service for the cloud. In this Video, you use
#Azure PowerShell to subscribe to Blob storage events, trigger an event, and view the result.
#Typically, you send events to an endpoint that processes the event data and takes actions.
#However, to simplify this article, you send the events to a web app that collects and displays the messages
#Create a resource group
$resourceGroup = "gridResourceGroup"
New-AzResourceGroup -Name $resourceGroup -Location $location
#Create a storage account
$storageName = "$($prefix)sa$id"
$storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroup `
-Name $storageName `
-Location $location `
-SkuName Standard_LRS `
-Kind BlobStorage `
-AccessTier Hot
$ctx = $storageAccount.Context
#Create a message endpoint
$sitename="twcontosotom75"
New-AzResourceGroupDeployment `
-ResourceGroupName $resourceGroup `
-TemplateUri "https://raw.githubusercontent.com/Azure-Samples/azure-event-grid-viewer/master/azuredeploy.json" `
-siteName $sitename `
-hostingPlanName viewerhost
#Enable Event Grid resource provider
Register-AzResourceProvider -ProviderNamespace Microsoft.EventGrid
Get-AzResourceProvider -ProviderNamespace Microsoft.EventGrid
#Subscribe to your storage account
$storageId = (Get-AzStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageName).Id
$endpoint="https://$sitename.azurewebsites.net/api/updates"
New-AzEventGridSubscription `
-EventSubscriptionName gridBlobQuickStart `
-Endpoint $endpoint `
-ResourceId $storageId
#Trigger an event from Blob storage
$containerName = "gridcontainer"
New-AzStorageContainer -Name $containerName -Context $ctx
echo $null >> gridTestFile.txt
Set-AzStorageBlobContent -File gridTestFile.txt -Container $containerName -Context $ctx -Blob gridTestFile.txt
#Clean up resources
Remove-AzResourceGroup -Name $resourceGroup -Force