Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An Http Triggered Javascript Azure Function to process event grid events. If it's a validation event, send back the validationCode to event grid.
module.exports = function (context, req) {
for (var events in req.body) {
var body = req.body[events];
if ( && body.eventType == "Microsoft.EventGrid.SubscriptionValidationEvent") {
context.log("event grid validation event, validation code: " +;
//validate header
if(req.headers['aeg-event-type'] && req.headers['aeg-event-type'] == 'SubscriptionValidation')
// Do any additional validation (as required) and then return back the below response
var code =;
context.res = { status: 200, body: { "ValidationResponse": code } };
context.res = { status: 400, body: "Validation header is missing." };
//for all other events, do the processing you need to do, such as call another azure function
// or a logic app, send alerts, or emails etc.
// create a response body, with the properties you're interested in, or just send the event in response.
let responseBody = {
"eventType": body.eventType,
"subject": body.subject
context.log("Resoonse body", responseBody);
context.res = { status: 200, body: responseBody };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.