Skip to content

Instantly share code, notes, and snippets.

Embed
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.data && body.eventType == "Microsoft.EventGrid.SubscriptionValidationEvent") {
context.log("event grid validation event, validation code: " + body.data.validationCode);
//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 = body.data.validationCode;
context.res = { status: 200, body: { "ValidationResponse": code } };
}
else{
context.res = { status: 400, body: "Validation header is missing." };
}
}
else{
//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,
"operationName": body.data.operationName,
"resourceProvider": body.data.resourceProvider,
"resourceUri": body.data.resourceUri,
"status": body.data.status,
"subject": body.subject
"subscriptionId": body.data.subscriptionId,
"tenantId": body.data.tenantId,
};
context.log("Resoonse body", responseBody);
context.res = { status: 200, body: responseBody };
}
}
context.done();
};
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.