Skip to content

Instantly share code, notes, and snippets.

@jeffhollan
Created December 20, 2017 07:55
Show Gist options
  • Select an option

  • Save jeffhollan/b33c3b6b12e6dc8a4ef0ff178e0a8e8f to your computer and use it in GitHub Desktop.

Select an option

Save jeffhollan/b33c3b6b12e6dc8a4ef0ff178e0a8e8f to your computer and use it in GitHub Desktop.
Emit Event to Event Grid from an Azure Function
function EmitEvent(ringEvent, context, callback) {
context.log('Sending event to event grid.');
var eventGridPayload = [{
id: utils.generateUUID(),
eventType: ringEvent['kind'],
subject: 'ring/frontDoor',
eventTime: new Date().toISOString(),
data: ringEvent
}];
var response = '';
var req = https.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
response += chunk;
});
res.on('end', () => {
context.log(response);
callback(response);
});
});
req.write(JSON.stringify(eventGridPayload));
req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment