Microservices, Docker deploy and Microservices source code in C#
Azure functions - Build apps faster with serverless architecture
1. Azure Functions: Building apps faster
with a serverless architecture
Callon Campbell
Systems Architect
2. Microsoft Azure
About me
Callon Campbell
Systems Architect / Developer. 19 years of
experience developing desktop, mobile and web
enterprise applications using .NET Framework, SQL
Server and Azure technologies.
Co-founder of ReflectInsight, a.NET logging
framework and with a real-time Live Log Viewer.
2
Email: CallonCampbell@Outlook.com Twitter: @Flying_Maverick
Blog: http://TheFlyingMaverick.com LinkedIn: LinkedIn.com/in/calloncampbell
Website: http://ReflectInsight.com Slideshare: https://www.slideshare.net/calloncampbell
3. Microsoft Azure
Agenda
•Overview of Azure Functions and serverless
•Tooling
•Build, deploy and monitor
•Common scenarios
•Best practices
•Wrap up
3
4. Microsoft Azure
What is Azure Functions?
• Azure Functions are a serverless event driven compute on
demand experience
• Think of Azure Functions as…
• C#, Node.js and Java
• Visual Studio, VS Code and CLI tooling
9. Microsoft Azure
Integrations
• Azure Functions can be
triggered by virtually any
event in Azure, other 3rd
party services or even from
on-premise systems
• These services can trigger
your function (startup) or
serve as input and output
for your code
11
Supported Integrations
• CosmosDB
• Event Hubs
• Mobile Apps (tables)
• Notification Hubs
• Service Bus (queues, topics)
• Storage (blob, queues, tables)
• GitHub (webhooks)
• Twilio (SMS messages)
• On-premises (using Service Bus)
11. Microsoft Azure
Securing your Azure Functions
HttpTriggers can be protected by Oauth providers
such as:
• Azure Active Directory
• Microsoft Account
• Facebook
• Google
• Twitter
13
13. Microsoft Azure
Function timeouts
•On a Consumption plan, a function can run for a
maximum of 10 minutes, with a default timeout of 5
minutes.
•The value can be increased changing the property
functionTimeout in host.json.
•For longer running functions use the App Service
Plan and/or Durable Functions.
15
31. Microsoft Azure
Serverless mobile backends
A mobile backend can be just a set of HTTP APIs that
are called from a mobile client using the WebHook
URL.
45
35. Microsoft Azure
Summary
• With Azure Functions, the focus is on the code and not
managing the infrastructure.
• When used as the serverless compute component of a
serverless architecture, you have the following benefits:
• Reduced time to market
• Lower total cost of ownership
• Pay per execution
58
36. Microsoft Azure
Azure serverless compute
•It’s now becoming easier than ever to create small,
targeted microservice architecture using a variety of
services
•Azure provides many services that can help you
achieve a low-friction, high-throughput and low-cost
solution
•Azure Functions, Logic Apps, Event Grid are just a
few in the serverless architecture family
59
39. Microsoft Azure
What’s next?
•Try Logic Apps for free: http://aka.ms/logicapps-try
•Blog: https://blogs.msdn.microsoft.com/logicapps/
•Twitter: @LogicAppsIO
•Learn more at Microsoft Virtual Academy and
Channel 9
62
40. Microsoft Azure
References
• https://azure.microsoft.com/en-us/services/functions/
• https://functions.azure.com/
• https://portal.azure.com/
• https://docs.microsoft.com/en-us/azure/azure-functions/
• https://azure.microsoft.com/en-us/pricing/details/functions/
• Azure Functions in Practice
• Azure - Serverless Architecture with Azure Functions
• Visual Studio Tools for Azure Functions Preview
• Azure Storage Explorer
63
Editor's Notes
Overview – Serverless and what are Azure Functions
Dev tooling – Tools along with deployment and monitoring capabilities
Azure Functions is an event driven, compute-on-demand experience. Basically just provide your code and Azure takes care of the rest.
When an event happens, Azure will automatically take care of everything to run that code at scale.
Azure functions can even runs EXE’s or call into DLL’s
First and foremost its an abstractions of servers.
Don’t need to worry about optimizing which operating system to run on, patching, etc
Don’t need to worry about optimizing utilization and scaling up and down for demand
Event driven process
Tell Azure how or when to run your code (is it based on a schedule, or when a new customer is added to salesforce, or when items are added to a queue, a table or storage, etc)
Micro build
You’re only charged for the usage.
Dynamically and elastically scale to meet demand.
Allows you as the developer to focus on your business logic. Everything else is taken cared for you.
This drastically increases time to market.
Reduce time to market
Innovate on new features
Enables you to be more competitive
Key take away is that Azure Functions gets all the benefits of using Azure App Service.
Any number of input and output bindings, but only have a single trigger.
Only HttpTriggers can be protected.
With runtime v2 you can now host on Windows or Linux (in preview)
Supports remote debugging for C# only.
Executing locally is handled by the Azure Functions CLI
When you’re ready it provides the capability to publish to Azure.
https://portal.azure.com/
I’ll now show you how to get started creating and running a simple HttpTrigger function from the Azure Portal.
https://portal.azure.com/
I’ll now show you how to get started creating and running a simple HttpTrigger function from the Azure Portal.
Use the QuickStart process to create a premade function or using the left side navigation, create your own custom function.
There are a number of templates available for different languages including some prebuilt samples. Looking at these samples and experiment functions is a great way to see what you can do.
When you’re function is ready, save and run it immediately in the portal and see the output in the logs.
You can also test your functions from the right navigation pane.
File -> New Project, look under Cloud and then select “Azure Functions (Preview)”.
Storage account connection should be “AzureWebJobsStorage”. You will then add your connection string to that keys value in the AppSettings.
AppSettings are shared across functions.
Using the Azure Storage Explorer, I can get my connection string for the storage account. Get Primary Connection String and add to AppSettings to key “AzureWebJobsStorage”.
I can also insert some sample test data to be consumed by my function.
Adjust timing polling.
Open up Host.json and using intellisence, add “queues” : {“maxPollingInterval”: 1000} where this value is in milliseconds.
https://portal.azure.com/
I’ll now show you how to get started creating and running a simple HttpTrigger function from the Azure Portal.
https://portal.azure.com/
I’ll now show you how to get started creating and running a simple HttpTrigger function from the Azure Portal.
Can choose ASP.NET core for Azure Functions
For example, you could execute code that runs every 15 minutes and cleans up a database table based on custom business logic.
For example, you could execute a function that reads newly discovered log files in an Azure Blob Storage container. The data can then be transformed into a row in an Azure SQL Database table, or DocumentDB or perhaps feed it into another service.
C# Azure Function for reacting to Azure Insights Events
For example, when a file is saved in OneDrive, this triggers a function that uses the Microsoft Graph API to modify the spreadsheet, creating additional charts and calculated data.
The app calls functions using the WebHook URL, saving user data and deciding what data to display. Or, you can do simple customizations, such as changing an ad based on user profile information.
Node.js Azure Function for generating SAS tokens C# Azure Function for generating SAS tokens
For example, a mobile application could capture an image, then call an Azure Function to get an access token for uploading to blob storage. A second Azure Function is triggered by the blob upload and resizes the image to be mobile-friendly.
For example, IoT devices send messages to Azure Stream Analytics, which then calls an Azure Function to transform the message. This function processes the data and creates a new record in an Azure SQL Database.
For example, you can create an Azure Function that processes a message using Cortana Analytics and call this function using the Microsoft Bot Framework.
Smallest unit of logic
Single scope of work
Keep dependencies to a minimum
Azure Functions should be SINGLE PURPOSE in nature. Think of them as short concise statements rather than compound sentences.
Azure Functions should be IDEMPOTENT in nature. This means that the resulting state of the function should be identical if called subsequent times with the same parameters.
Azure Functions should be quick and short lived - keeping execution time brief. For longer running jobs consider using Azure WebJobs or hosting the service in Azure Service Fabric.
Start small and look at replacing a single API or perhaps a background processing item.
Integration is another great place to start as it’s often a new layer on top of old existing layers.
On a Consumption compute plan, you are currently limited to 5 minutes of computation. On a regular App Service Plan, running for 10 minutes is quite reasonable. Long-running functions is more on the order of an hour.
Resource consumption in GB-s (gigabyte-seconds) is computed as a combination of memory size and execution time for all functions running in a Function App.
Executions counted each time a function is executed in response to an event, triggered by a binding.