README.md

DEV50: Investing in Serverless: Less Servers, More Code.

Sometimes all you need is a few routines to run in response to a series of events – so why do you need to choose a development framework, deployment strategy and server setup for such a simple need? Wouldn’t it be great if you could just write the simple routines you need and have them run exactly when you need them and scale automatically? Turns out you can with the right cloud services.

In this talk we’ll create a set of routines that run on Azure Functions and respond to events in Azure Event Grid. We’ll then orchestrate these functions and messages using Azure Logic Apps.

Navigate to the "tailwindtraders-inventory" functions app, wait for the functions list to expand, then click on Monitor

Click on the Add Event Grid Subscription link

Subscribe to the "inventory" topic to monitor events generated by the CLI tool

Repeat the subscription for the Process function

It is recommended you walk through the two logic apps steps to pre-initialize connection information. You can then delete all steps and start with a blank workflow but the connectors will then default and not re-prompt you for credentials.

Note: be sure you had added two subscriptions to the custom event topic: one for the serverless endpoint named Monitor and one for the serverless endpoint named Process. The second subscription is required for the durable functions workflow to work.

Demos

First demo: serverless auto-scale

Open application insights and open Live Metrics Stream. Collapse Outgoing Requests and Overall Health

Second demo: serverless messaging and functions

Note: for this demo, the preferred log stream is the one scoped to the specific function endpoint. If you open the logs from the main function app tab, you will see streams for all functions which may be confusing to explain to the audience. If you click on the function itself, there is a tab at the bottom for logs that you can click on then expand to show it.

Open the Monitor function in the portal and open the live-streaming logs

Add a new SKU dotnet run add 2181

Show the message picked up by the function

Set the price for the SKU dotnet run set-price 2181 9.99

Show the same message

Open the code in the Notifications project and show how the events are raised, explain this can be done from any platform that supports an HTTPS POST

Note: the code will not appear in the portal because it is a compiled function. Use Visual Studio or Visual Studio Code to display the source code for the function.

Navigate to the subscription in the portal and show the analytics

Navigate to the function app and use the Monitor tab to show how telemetry is saved (explain it is integrated with Application Insights as well)

Click on the "Add Event Subscription" button and explain the subscription process

Third demo: durable serverless workflows

Open storage explorer and navigate to the inventory table. Focus on the 2181 entry.

Execute dotnet run get 2181 to show the CLI output, .e.g:

Walk through the code for Process (listens for events, kicks off a workflow on the Added event, publishes messages to the workflow for other events)

Walk through the code for SkuWorkflow and explain the tasks can come in asynchronously and the workflow will "sleep" until it is needed

Open the Monitor tab for SkuWorkflow in the portal and show the messages already sent from the previous demo (basically it was kicked off and received the price event)

Switch to the live logs for the SkuWorkflow function

Let the audience choose what order you perform steps 7-8 and 9 (image first, or description?)

Set a description: dotnet run describe 2181 "A black glove."

Show the notification come through

Finally, upload the image for the SKU: dotnet run set-image 2181 2181.jpg

Show the notification ends the workflow

Refresh storage explorer and show the SKU turned to active

Fourth demo: logic apps to trigger email

Open the tailwindtraders-email logic app and click on the Logic App Designer

Choose an Event Grid Trigger to start

Sign in and specify the custom inventory topic

Add a custom Event Type of Added

Add a new "Parse JSON" step

Pull from the event grid "data" object and specify the schema

{
"type": "object",
"properties": {
"Sku": {
"type": "string"
}
}
}

Add a new "Office 365 Outlook - Send Email" step

Authenticate and configure the email

Save the logic app

Use the CLI to add a new SKU, for example: dotnet run add 2085

Verify an email arrives!

Fifth demo: logic apps to identify images

Open the tailwindtraders-captioner logic app and click on the Logic App Designer

Add a new Computer Vision API step (describe image, not URL or content) and add the endpoint and keys

Choose image URL for source and specify the URL passed in the event grid event

Choose Azure Functions

Navigate to the MachineDescription function

Add the JSON payload (SKU based on the incoming event grid payload, and description based on the Captions Caption Text)

It's OK if you're prompted to add a for loop around the step because multiple captions may be returned.

Save it and use the CLI to add an image: dotnet run set-image 2085 2085.jpg

Verify the machine description is updated! (dotnet run get 2085)

This is a non-trained model. For this reason, 2085 (hammer) should property register as a tool but the others will have poor captions. That's OK ... explain this is why we have human verification and that the model can be trained on a dataset to get more accurate. Go into the logic apps history and show the list of tags and confidence levels.

Tailwind Traders Command Line Tool

This tool is located in the CLI directory. Commands should be run from the root of the folder. All commands start with dotnet run to kick off the program.

Initialize database

This deletes the table from table storage and repopulates it. It assumes the images for the SKUs are in the parent directory from where the command is run (the CLI folder). A SKU is the unique identifier of an inventory item.

dotnet run init

It can take up to several minutes for the table to delete, so if you see a "Conflict... retry" loop don't worry, it should eventually continue once the table is confirmed deleted.

Get SKU information

This retrieves information about a SKU.

dotnet run get <sku>

Example:

dotnet run get 2053

Add a new SKU

Adds a new SKU to the database.

dotnet run add <sku>

When a new SKU is added, it has no price, human-verified description or image. Subsequent commands can set these attributes. The SKU should automatically get set to active status after all three attributes are set.

Example:

dotnet run add 2085

Set the description for a SKU

Sets the human description for a SKU (overrides any machine-generated description).

dotnet run describe <sku> "<description>"

Example:

dotnet run describe 2085 "A very handy hammer."

Set the price of a SKU

Sets the price of the inventory item.

dotnet run set-price <sku> <price>

Example:

dotnet run set-price 2085 9.99

Upload an image for the SKU

Uploads an image to blob storage and adds the URL of the image to the SKU.

dotnet run set-image <sku> <image>

Note that image is expected to be in the current directory. Only the local filename is needed.

Example:

dotnet run set-image 2085 2085.jpg

Teardown

To remove all resources created for this session you can delete the resource group you created earlier using the Azure CLI: