Skip to content

Latest commit

 

History

History
90 lines (71 loc) · 3.57 KB

06-PortalFunctions.md

File metadata and controls

90 lines (71 loc) · 3.57 KB

Challenge 6 - Create Functions in the Portal

Prerequisities

  1. Challenge 5 - Deployment should be done successfuly.

Introduction

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.

  1. Navigate to the function app "Events"

  2. Create a function that is triggered by event grid (install extensions if prompted)

    • Name : SavePlateData
  3. 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();
    };
  4. 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 : Leave As Is
  5. 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
  6. Create another function that is triggered by event grid

    • Name : QueuePlateForManualCheckup
  7. 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();
    };
  8. 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
    • Leave Azure Function as the Endpoint Type.
  9. Add a Cosmos DB Output to the QueuePlateForManualCheckup function

    • Select the Cosmos DB account connection created earlier
    • Database Name : LicensePlates
    • Collection Name : NeedsManualReview

Success Criteria

  1. Both functions do not have any compillation errors
  2. Both functions have event grid subscriptions
  3. Both functions have Cosmos DB as their outputs

Tips

Description Links
Create your first function in the Azure portal https://docs.microsoft.com/azure/azure-functions/functions-create-first-azure-function
Store unstructured data using Azure Functions and Azure Cosmos DB https://docs.microsoft.com/azure/azure-functions/functions-integrate-store-unstructured-data-cosmosdb

Next challenge (Monitoring) >