Azure Functions allow processing of events with serverless code. Functions can be triggered by events and input/output can be bound to various Azure and third party services. Functions support C#, Node.js, Python and more. The Consumption plan charges per execution while the App Service plan runs Functions on dedicated VMs. Functions are ideal for building serverless web/mobile backends and processing IoT/real-time streams.
2. Microsoft Azure
About me
Callon Campbell
Full-stack developer / technical lead. With over 19 years of experience
developing desktop, mobile and web enterprise applications using Microsoft
.NET Framework, SQL Server and Azure technologies.
I have a passion for both frontend development, specifically with Angular
and Microsoft's Universal Windows Platform (UWP) and also in the cloud
with Microsoft Azure. I blog, tweet and aspire to get an MVP in Azure.
Co-founder of ReflectSoftware Inc and one the principle developers of
ReflectInsight, a real-time .NET logging/analytics framework and Live/Log
Viewer.
2
Email: CallonCampbell@Outlook.com Twitter: @Flying_Maverick, @DevelopAzure
Blog: TheFlyingMaverick.com LinkedIn: LinkedIn.com/in/calloncampbell
Website: ReflectInsight.com
4. Microsoft Azure
What is Azure?
Microsoft Azure is a flexible, open, and secure public cloud built for business.
Any number of consumable services can be chained together to form an entire
application.
4
5. 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 is the newest service in the
serverless architecture family
5
7. Microsoft Azure
What is Azure Functions?
• Azure Functions are a serverless, event driven experience
that extends the existing Azure App Service platform
• Azure Functions are “nanoservices” that can scale based
on demand (only paying for the resources you use)
• Think of Azure Functions as…
8. Microsoft Azure
What is Azure Functions (cont’d)
• Serverless
• Don’t worry about the infrastructure and provisioning of servers,
especially when your Functions call rate scales up
• Accelerate development
• Write your code in the portal for immediate execution
• Quickly and easily iterate with continuous deployment (Visual Studio
Team Services, GitHub, BitBucket)
• Bind into services
• Easily add bindings to Azure services and external services (Box,
DropBox, OneDrive, SendGrid, …) to get input into or output from your
Azure Functions
8
10. Microsoft Azure
Features of Azure Functions
• Choice of language
• Pay-per-use pricing model
• Bring your own dependencies (NuGet, NPM)
• Integrated security
• Simplified integration
• Flexible development / deployment
• Open-source
• Very close to the metal, quickly caches and uncaches
10
11. Microsoft Azure
Supported languages and tools
•Azure Functions can be created in C#,
Node/JavaScript, Python, F#, PHP and scripting
languages like PowerShell, Batch and Bash
•Azure Functions can even run EXE’s or call into DLL’s
11
12. Microsoft Azure
What can I do with Azure Functions?
•Azure Functions are great for processing data,
integrating systems, working with IoT, simple API’s
and microservices
•Azure Functions provide templates for a number of
key scenarios
•Azure Functions supports
• Triggers - a way to start execution
• Bindings - a way to simplify code for input and output of
data
12
13. 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
13
Supported Integrations
• DocumentDB
• 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)
14. Microsoft Azure
Available trigger templates
• BlogTrigger
• EventHubTrigger
• Generic webhook
• GitHub webhook
• HttpTrigger*
• QueueTrigger
• ServiceBusQueueTrigger
• ServiceBusTopicTrigger
• TimerTrigger
* Every function type with the exception of the HttpTrigger type will require a storage account.
14
15. Microsoft Azure
Triggers and bindings
15
• A function can have any number
of input and output bindings
but can only have a single
trigger binding.
• The following is a list of
different triggers and their
available bindings:
16. Microsoft Azure
Securing your Azure Functions
HttpTriggers can be protected by Oauth providers
such as:
• Azure Active Directory
• Microsoft Account
• Facebook
• Google
• Twitter
16
18. Microsoft Azure
Code and test Azure Functions locally
•Working in the Azure Portal is great but lacks the
following key components:
• Debugging
• Source control integration
• Continuous deployment
•Wouldn’t it be nice if we could use Visual Studio…
22
19. Microsoft Azure
Introducing Visual Studio Tools for Azure
Functions
• Provides local development and tooling experience
(currently in preview)
• Only available for VS2015 (will come to VS2017 after
VS2017 releases)
• Remote debugging is supported in C# only (for now)
• Running locally is handled by the Azure Functions CLI
• Provides publish to Azure
23
23. Microsoft Azure
Approach to building functions
When building your Azure Functions consider this…
“A key to realizing the full value is to write only the
smallest unit of logic to do a single scope of work and
to keep the dependencies to a minimum.”
– Joseph Fultz and Darren Brust, MSDN Magazine
33
25. Microsoft Azure
Where to get started
•Start small, replace 1 API or background processing
item
•Integration is a great place, often it’s a new layer on
top of old layers
35
26. Microsoft Azure
Scaling & runtime best practices
• E2E performance testing
• Know the limits of the service
• Reduce, Reuse and Recycle your resources
• Functions in a Function App share memory
• A Singleton can be shared across many Functions (i.e. DB
connection pooling, Redis caches, etc)
• Be mindful of what you load – memory is averaged over
your functions
• Get rid of data/objects you don’t need
36
32. 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.
44
36. Microsoft Azure
Pricing
•No upfront cost
•No termination fees
•Pay only for what you use
Only pay for the time your code is running. You’ll be
charged based on the number of resources your
Azure Functions needs, and only for as long as it
takes your code to execute.
48
37. Microsoft Azure
Two kinds of pricing plans
Consumption plan - When your function runs, Azure
provides all of the necessary computational resources. You
don't have to worry about resource management, and you
only pay for the time that your code runs.
App Service plan - Run your functions just like your web,
mobile, and API apps. When you’re already using App
Service for your other applications, you can also run your
functions on the same plan at no additional cost.
49
38. Microsoft Azure
Pricing - Consumption Plan
• The Consumption Plan is billed based on resource consumption
and executions
• Consumption Plan pricing includes a monthly free grant of 1 million
requests and 400,000 GB-s of resource consumption per month:
• This is the recommended plan for scale…but set your limits!
50
39. Microsoft Azure
Pricing - App Service Plan
• Your functions run on dedicated VMs
• Dedicated VM’s are allocated to your App Service apps and
function apps are always available whether code is actively
running or not
• Good option if you have under utilized VMs
• A VM decouples the cost from both runtime and memory
size – you can limit the cost for long- running functions to
the cost of the VMs they run on
51
41. Microsoft Azure
Summary
•With Azure Functions, the focus is on the code and
not managing the infrastructure.
•Azure Functions are a key ingredient to serverless
compute that is often required for the benefits of
PaaS implementations.
53
42. Microsoft Azure
Several key benefits
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
54
45. 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
57
Editor's Notes
How many people here know what Azure is?
How many people have used Azure?
Anyone know what Azure Functions are?
In Azure there are many consumable services that can be chained together to form an entire application.
Other serverless Azure services are:
Azure Functions
Azure Logic Apps
Azure Service Fabric
Azure Batch
Reference:
https://www.simple-talk.com/cloud/cloud-development/serverless-architecture-azure/
A new key component of these consumable services is Azure Functions which was introduced last year (2016) at the Microsoft Build developer conference.
Microsoft touts Azure Functions as part and parcel of Azure's PaaS solutions portfolio, used primarily for event-driven, pay-as-you-go computing at scale.
Azure Functions can provide the serverless compute capability in a complete solution ecosystem.
Platform as a service (PaaS) is a complete development and deployment environment in the cloud, with resources that enable you to deliver everything from simple cloud-based apps to sophisticated, cloud-enabled enterprise applications.
Like IaaS, PaaS includes infrastructure—servers, storage, and networking—but also middleware, development tools, business intelligence (BI) services, database management systems, and more. PaaS is designed to support the complete web application lifecycle: building, testing, deploying, managing, and updating.
PaaS allows you to avoid the expense and complexity of buying and managing software licenses, the underlying application infrastructure and middleware or the development tools and other resources. You manage the applications and services you develop, and the cloud service provider typically manages everything else.
Azure Functions is an event driven, compute-on-demand experience. You can leverage Azure Functions to build HTTP endpoints accessible by mobile and IoT devices.
Azure Functions can be considered “nanoservices” that can scale based on demand.
With serverless, you don’t need to worry about the infrastructure and provisioning of servers.
Setup continuous deployment of your functions from Visual Studio Tea Services, GitHub and BitBucket.
Easily add bindings to Azure or external services.
Key take away is that Azure Functions gets all the benefits of using Azure App Service.
Protect HTTP-triggered functions with OAuth providers such as Azure Active Directory, Facebook, Google, Twitter, and Microsoft Account.
Easily leverage Azure services and other software-as-a-service (SaaS) offerings.
Code your functions right in the portal or set up continuous integration and deploy your code through GitHub, Visual Studio Team Services, and other supported development tools.
The Functions runtime is open-source and available on GitHub
Take that console application you already have an upload it to run as an Azure Function.
Every function type with the exception of the http trigger type will require a storage account.
Any number of input and output bindings, but only have a single trigger.
Only HttpTriggers can be protected.
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.
Visual Studio tooling for Azure Functions provides local development and debugging experience.
Currently in preview and only available for Visual Studio 2015 (coming soon to VS2017).
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.
I’ll now create a new Azure Function app in Visual Studio, run and debug it locally using the Azure Functions CLI and finally I’ll publish it up to Azure.
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.
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.
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.
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.