< Previous Challenge - Home - Next Challenge >
Create two new Azure Functions written in Node.js, using the Azure portal. These will be triggered by Event Grid and output to Azure Cosmos DB to save the results of license plate processing done by the ProcessImage function.
-
Navigate to the function app "Events"
-
Create a function that is triggered by event grid (install extensions if prompted)
- Name : SavePlateData
-
Replace the code with the following:
module.exports = function(context, eventGridEvent) { context.log(typeof eventGridEvent); context.log(eventGridEvent); context.bindings.outputDocument = { fileName: eventGridEvent.data['fileName'], licensePlateText: eventGridEvent.data['licensePlateText'], timeStamp: eventGridEvent.data['timeStamp'], exported: false }; context.done(); };
-
Add an event grid subscription
- Name should contain "SAVE"
- Event Schema: Event Grid Schema.
- Topic Type: Event Grid Topics.
- Resource: your recently created Event Grid.
- Event Type : Add
savePlateData
- Endpoint : Select SavePlateData Function.
-
Add a Cosmos DB Output to the function (install extensions if needed)
- Select the Cosmos DB account created earlier
- Database Name : LicensePlates
- Collection Name : Processed
-
Create another function that is triggered by event grid
- Name : QueuePlateForManualCheckup
-
Replace the code with the following:
module.exports = async function(context, eventGridEvent) { context.log(typeof eventGridEvent); context.log(eventGridEvent); context.bindings.outputDocument = { fileName: eventGridEvent.data['fileName'], licensePlateText: '', timeStamp: eventGridEvent.data['timeStamp'], resolved: false }; context.done(); };
-
Add an event grid subscription
- Name should contain "QUEUE"
- Event Schema: Event Grid Schema.
- Topic Type: Event Grid Topics.
- Resource: your recently created Event Grid.
- Add Event Type
queuePlateForManualCheckup
- Endpoint: Select QueuePlateForManualCheckup Function.
-
Add a Cosmos DB Output to the QueuePlateForManualCheckup function
- Select the Cosmos DB account connection created earlier
- Database Name : LicensePlates
- Collection Name : NeedsManualReview
- Both functions do not have any compillation errors
- Both functions have event grid subscriptions
- Both functions have Cosmos DB as their outputs