Skip to content

Instantly share code, notes, and snippets.

@ehrnst
Last active August 3, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehrnst/3fecfa65fad3e55a914dadd4282b6cd3 to your computer and use it in GitHub Desktop.
Save ehrnst/3fecfa65fad3e55a914dadd4282b6cd3 to your computer and use it in GitHub Desktop.
azure function return event grid validation event
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
## validate event grid as described in https://docs.microsoft.com/en-us/azure/event-grid/security-authentication
# check event type and return a Json object with the correct validation response
if ($requestBody.eventType -eq "Microsoft.EventGrid.SubscriptionValidationEvent") {
$code = $requestBody.data.validationCode
$content = @{ validationResponse = $code }
$message = convertto-json -compress -InputObject ([ordered]@{
body = $content
statusCode = 200
})
Out-File -Encoding Ascii -FilePath $res -inputObject $($message)
write-output $message
}
## continue main script
# Get event grid data
$data = $requestBody.data
$name = $data.name
Out-File -Encoding Ascii -FilePath $res -inputObject "hello $name"
write-output "hello $name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment