Skip to content

Commit fa03c83

Browse files
authored
Merge pull request #278531 from spelluru/egridkeynote0617
Event Grid SAS key length
2 parents c151fbc + 516c2f4 commit fa03c83

File tree

5 files changed

+93
-10
lines changed

5 files changed

+93
-10
lines changed

articles/event-grid/get-access-keys.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
title: Get access key for an Event Grid resource
33
description: This article describes how to get access key for an Event Grid topic or domain
44
ms.topic: how-to
5-
ms.date: 07/07/2020
5+
ms.date: 06/17/2024
66
ms.custom: devx-track-azurepowershell, devx-track-azurecli
77
ms.devlang: azurecli
88
---
99

1010
# Get access keys for Event Grid resources (topics or domains)
11-
Access keys are used to authenticate an application publishing events to Azure Event Grid resources (topics and domains). We recommend regenerating your keys regularly and storing them securely. You are provided with two access keys so that you can maintain connections using one key while regenerating the other.
11+
Access keys are used to authenticate an application publishing events to Azure Event Grid resources (topics and domains). We recommend regenerating your keys regularly and storing them securely. You're provided with two access keys so that you can maintain connections using one key while regenerating the other.
1212

1313
This article describes how to get access keys for an Event Grid resource (topic or domain) using Azure portal, PowerShell, or CLI.
1414

15+
> [!IMPORTANT]
16+
> From August 1, 2024 to August 10, 2024, Azure Event Grid will rollout a security improvement extending the Shared Access Signature (SAS) key length from 44 to 84 characters. This change is being made to strengthen the security of your data in Event Grid resources. The change doesn't impact any application or service that currently publishes events to Event Grid with the old SAS key but it may impact only if you regenerate the SAS key of your Event Grid topics, domains, namespaces, and partner topics, after the update.
17+
>
18+
> We recommend that you regenerate your SAS key on or after August 11, 2024. After regenerating the key, update any event publishing applications or services that use the old key to use the enhanced SAS key.
19+
1520
## Azure portal
1621
In the Azure portal, switch to **Access keys** tab of the **Event Grid Topic** or **Event Grid Domain** page for your topic or domain.
1722

@@ -31,13 +36,13 @@ Get-AzEventGridDomainKey -ResourceGroup <RESOURCE GROUP NAME> -Name <DOMAIN NAME
3136
```
3237

3338
## Azure CLI
34-
Use the [az eventgrid topic key list](/cli/azure/eventgrid/topic/key#az-eventgrid-topic-key-list) to get access keys for topics.
39+
Use the [`az eventgrid topic key list`](/cli/azure/eventgrid/topic/key#az-eventgrid-topic-key-list) to get access keys for topics.
3540

3641
```azurecli-interactive
3742
az eventgrid topic key list --resource-group <RESOURCE GROUP NAME> --name <TOPIC NAME>
3843
```
3944

40-
Use [az eventgrid domain key list](/cli/azure/eventgrid/domain/key#az-eventgrid-domain-key-list) to get access keys for domains.
45+
Use [`az eventgrid domain key list`](/cli/azure/eventgrid/domain/key#az-eventgrid-domain-key-list) to get access keys for domains.
4146

4247
```azurecli-interactive
4348
az eventgrid domain key list --resource-group <RESOURCE GROUP NAME> --name <DOMAIN NAME>
98.5 KB
Loading
38 KB
Loading
70.9 KB
Loading

articles/event-grid/post-to-custom-topic.md

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: Post event to custom Azure Event Grid topic
33
description: This article describes how to post an event to a custom topic. It shows the format of the post and event data.
4-
ms.topic: conceptual
5-
ms.date: 01/18/2024
4+
ms.topic: concept-article
5+
ms.date: 06/18/2024
6+
#customer intent: As a developer, I want to know how to publish events to an Azure Event Grid custom topic
67
---
78

89
# Publish events to Azure Event Grid custom topics using access keys
@@ -17,30 +18,48 @@ This article describes how to post an event to a custom topic using an access ke
1718

1819
When sending the HTTP POST to a custom topic, use the URI format: `https://<topic-endpoint>?api-version=2018-01-01`. For example, a valid URI is: `https://exampletopic.westus2-1.eventgrid.azure.net/api/events?api-version=2018-01-01`. To get the endpoint for a custom topic using Azure CLI, use:
1920

21+
# [Azure portal](#tab/azure-portal)
22+
You can find the topic's endpoint on the **Overview** tab of the **Event Grid Topic** page in the Azure portal.
23+
24+
:::image type="content" source="./media/post-to-custom-topic/topic-endpoint.png" alt-text="Screenshot that shows the Event Grid topic page on the Azure portal with the topic endpoint highlighted." lightbox="./media/post-to-custom-topic/topic-endpoint.png":::
25+
26+
# [Azure CLI](#tab/azure-cli)
27+
2028
```azurecli-interactive
2129
az eventgrid topic show --name <topic-name> -g <topic-resource-group> --query "endpoint"
2230
```
2331

24-
To get the endpoint for a custom topic using Azure PowerShell, use:
32+
# [Azure PowerShell](#tab/azure-powershell)
2533

2634
```powershell
2735
(Get-AzEventGridTopic -ResourceGroupName <topic-resource-group> -Name <topic-name>).Endpoint
2836
```
2937

38+
---
39+
3040
## Header
3141

3242
In the request, include a header value named `aeg-sas-key` that contains a key for authentication. For example, a valid header value is `aeg-sas-key: xxxxxxxxxxxxxxxxxxxxxxx`. To get the key for a custom topic using Azure CLI, use:
3343

44+
# [Azure portal](#tab/azure-portal)
45+
To get the access key for the custom topic, select **Access keys** tab on the **Event Grid Topic** page in the Azure portal.
46+
47+
:::image type="content" source="./media/post-to-custom-topic/custom-topic-access-keys.png" alt-text="Screenshot that shows the Access Keys tab of the Event Grid topic page on the Azure portal." lightbox="./media/post-to-custom-topic/custom-topic-access-keys.png":::
48+
49+
# [Azure CLI](#tab/azure-cli)
50+
3451
```azurecli
3552
az eventgrid topic key list --name <topic-name> -g <topic-resource-group> --query "key1"
3653
```
3754

38-
To get the key for a custom topic using PowerShell, use:
55+
# [Azure PowerShell](#tab/azure-powershell)
3956

4057
```powershell
4158
(Get-AzEventGridTopicKey -ResourceGroupName <topic-resource-group> -Name <topic-name>).Key1
4259
```
4360

61+
---
62+
4463
## Event data
4564

4665
For custom topics, the top-level data contains the same fields as standard resource-defined events. One of those properties is a `data` property that contains properties unique to the custom topic. As an event publisher, you determine properties for that data object. Here's the schema:
@@ -60,7 +79,7 @@ For custom topics, the top-level data contains the same fields as standard resou
6079
]
6180
```
6281

63-
For a description of these properties, see [Azure Event Grid event schema](event-schema.md). When posting events to an Event Grid topic, the array can have a total size of up to 1 MB. The maximum allowed size for an event is also 1 MB. Events over 64 KB are charged in 64-KB increments. When receiving events in a batch, the maximum allowed number of events is 5,000 per batch.
82+
For a description of these properties, see [Azure Event Grid event schema](event-schema.md). When a client sends events to an Event Grid topic, the array can have a total size of up to 1 MB. The maximum allowed size for an event is also 1 MB. Events over 64 KB are charged in 64-KB increments. When a client receives events in a batch, the maximum allowed number of events is 5,000 per batch.
6483

6584
For example, a valid event data schema is:
6685

@@ -78,6 +97,65 @@ For example, a valid event data schema is:
7897
}]
7998
```
8099

100+
## Send the sample event
101+
This section shows how to send a sample event to the custom topic.
102+
103+
# [Azure portal](#tab/azure-portal)
104+
105+
1. In the [Azure portal](https://portal.azure.com), launch Cloud Shell.
106+
1. In the Cloud Shell, run the commands from the Azure PowerShell or Azure CLI in the **Bash** or **PowerShell** session.
107+
108+
:::image type="content" source="./media/post-to-custom-topic/cloud-shell.png" alt-text="Screenshot that shows the Cloud Shell in the Azure portal." lightbox="./media/post-to-custom-topic/cloud-shell.png":::
109+
110+
111+
# [Azure CLI](#tab/azure-cli)
112+
113+
```azurecli
114+
endpoint=$(az eventgrid topic show --name <topic name> -g <resource group name> --query "endpoint" --output tsv)
115+
116+
key=$(az eventgrid topic key list --name <topic name> -g <resource group name> --query "key1" --output tsv)
117+
118+
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"} ]'
119+
120+
curl -X POST -H "aeg-sas-key: $key" -d "$event" $endpoint
121+
```
122+
123+
# [Azure PowerShell](#tab/azure-powershell)
124+
125+
```azurepowershell
126+
$resourceGroupName = "<resource group name>"
127+
$topicName = "<topic name>"
128+
129+
$endpoint = (Get-AzEventGridTopic -ResourceGroupName $resourceGroupName -Name $topicName).Endpoint
130+
131+
$keys = Get-AzEventGridTopicKey -ResourceGroupName $resourceGroupName -Name $topicName
132+
133+
$eventID = Get-Random 99999
134+
#Date format should be SortableDateTimePattern (ISO 8601)
135+
$eventDate = Get-Date -Format s
136+
137+
#Construct body using Hashtable
138+
$htbody = @{
139+
id= $eventID
140+
eventType="recordInserted"
141+
subject="myapp/vehicles/motorcycles"
142+
eventTime= $eventDate
143+
data= @{
144+
make="Ducati"
145+
model="Monster"
146+
}
147+
dataVersion="1.0"
148+
}
149+
150+
#Use ConvertTo-Json to convert event body from Hashtable to JSON Object
151+
#Append square brackets to the converted JSON payload since they are expected in the event's JSON payload syntax
152+
$body = "["+(ConvertTo-Json $htbody)+"]"
153+
154+
Invoke-WebRequest -Uri $endpoint -Method POST -Body $body -Headers @{"aeg-sas-key" = $keys.Key1}
155+
```
156+
157+
---
158+
81159
## Response
82160

83161
After posting to the topic endpoint, you receive a response. The response is a standard HTTP response code. Some common responses are:
@@ -105,7 +183,7 @@ For errors, the message body has the following format:
105183
}
106184
```
107185

108-
## Next steps
186+
## Related content
109187

110188
* For information about monitoring event deliveries, see [Monitor Event Grid message delivery](monitor-event-delivery.md).
111189
* For more information about the authentication key, see [Event Grid security and authentication](security-authentication.md).

0 commit comments

Comments
 (0)