6. Azure Functions
“Accelerate your development with an event-driven,
serverless compute experience. Scale on demand and
pay only for the resources you consume.”
7. Azure Functions
• Accelerate & simplify development with Serverless compute
• Improve your end-to-end development experience
• Simplify complex orchestration challenges resolution
• Connect other services without hard-coding integrations for faster
solutions development
• Choose the best hosting option for your application
• Develop your way
10. Consumption plan
• The default hosting plan
• Pay only when your Functions are running
• Scale out automatically
• Billing is based on # of executions, execution time, and memory used
• GB-s: average memory size in gigabytes * execution time in ms
• Free grant: 1 million executions, 400.000 GB-s
11. App Service plan
• Consider if you want to
• Take advantage of existing, underutilized VMs
• Provide a custom image to run Functions on
• Enable Always On
• Runtime goes idle after a few minutes
• Only HTTP triggers “wake up” the Functions
12. Premium plan
• Consider if you want to
• Run function apps continuously, or nearly continuously
• Have more CPU or memory options than what is provided by the
Consumption plan
• Run your code longer than the max. on the Consumption plan
• Have features that are only available on a Premium plan (VNET/VPN)
• Billing is based on the number of vCPU-s and GB-s
14. Premium plan – Features
• Perpetually warm instances to avoid any cold start
• VNet connectivity
• Unlimited execution duration
• Premium instance sizes (one core, two core, and four core instances)
• More predictable pricing
• High-density app allocation for plans with multiple function apps
17. What is Kubernetes / AKS?
• Docker: Create, deploy and run applications in Containers
• Kubernetes (k8s): open source container orchestration engine
for automating deployment, scaling, and management of
containerized applications (e.g. Docker containers)
• Azure Kubernetes Service (AKS): Managed Kubernetes in Azure
17
20. Pods
• Unit of Deployment
• One or a few Containers
• Persistent volumes
20
21. Azure functions in AKS
• Add serverless capabilities with Virtual Nodes
• Scale Event driven applications with KEDA (preview)
• Scale HTTP driven applications with Osiris (experimental)
• Managed identity with AAD Pod Identity
21
22. Azure Functions in Kubernetes
The good news:
• Easy to write and small pieces of code
• Triggers and bindings
• Portable between all hosting options
The not-so-good news:
• You lose most of what you are used to with Azure Functions in the
portal
22
23. Azure Functions in Kubernetes – Pitfalls
• Scaling, without KEDA, does not work as expected
• Host ID different per Pod
• Poor fix by setting: AzureFunctionsWebHost:hostId
23
25. Triggers & Bindings
• Triggers
• cause a function to run
• function must have exactly one trigger
• have associated data, which is often provided as the payload of the function
• Bindings
• way of declaratively connecting another resource to the function
• may be connected as input bindings, output bindings, or both
• provide their data to the function as parameters
27. Dual abstraction
• Azure Functions abstract away the infrastructure
• Triggers & Bindings abstract away the resources you interact with
28. Triggers
• Example:
• Blob Trigger on a Consumption plan
• Up to 10 minute delay
Solution:
• Switch to App Service plan with Always On enabled.
• Use Event Grid trigger with your Blob storage account.
31. Dependency Injection
• Microsoft.NET.Sdk.Functions >= 1.0.28
• Constructor injection
• Same as DI in ASP.Net core
• Already provided services:
• Microsoft.Extensions.Configuration.IConfiguration
• Microsoft.Azure.WebJobs.Host.Executors.IHostIdProvider
32
32. DI – Scopes
• Singleton – Created once, on first request,
or when created before registration
• Scoped – Created once per client request (connection / trigger)
• Transient – Created on each request
33
33. DI – Extension
• NuGet: Microsoft.Azure.Functions.Extensions
• Makes dependency registrations a bit easier
• Provides IServiceCollection on IFunctionHostBuilder
34
34. DI – Migrating
35
public static class Function
{
[FunctionName(nameof(Ping))]
public static async Task<string> Ping(
[HttpTrigger(AuthorizationLevel.Function, "get"] HttpRequest req,
ILogger log,
CancellationToken cancellationToken)
{
var pingService = new PingService(log);
return await pingService.Ping(cancellationToken);
}
}
public class Function
{
private readonly IPingService _pingService;
public Function(IPingService pingService)
{
_pingService = pingService;
}
[FunctionName(nameof(Ping))]
public async Task<string> Ping(
[HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req,
CancellationToken cancellationToken)
=> await _pingService.Ping(cancellationToken);
}
35. DI – Registration
36
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
[assembly: FunctionsStartup(typeof(Startup))]
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddScoped<IPingService, PingService>();
}
}
38. Managed Identities for Azure resources
• Provide Azure services with a managed identity in Azure AD
• Use the identity to authenticate to any service
(that supports Azure AD authentication)
39. Supporting services
“We are in the process of integrating managed identities for Azure
resources and Azure AD authentication across Azure.”
• Azure Resource Manager
• Azure Key Vault
• Azure Data Lake
• Azure SQL
• Azure Event Hub
• Azure Service Bus
• Azure Storage blobs and queues
• Azure Analysis Services
After intro: who has worked with Azure Functions? Who has worked with Kubernetes/AKS?
GB-s: Gigabyte seconds
Memory used by a function is measured by rounding up to the nearest 128 MB, up to the maximum memory size of 1,536 MB,
With execution time calculated by rounding up to the nearest 1 ms.
Minimum: 100 ms and 128 mb
Also: dedicated plan
Regardless of the function app timeout setting, 230 seconds is the maximum amount of time that an HTTP triggered function can take to respond to a request.
Images are from a Serverless360.com blog post, and aren’t available without Jeff Hollan and Alex Karcher 🤣
https://phippy.io/
Images taken from Kubernetes site: https://kubernetes.io/docs/tutorials/kubernetes-basics/
AAD Pod Identity
E.g. manual scaling or scaling using HPA (Horizontal Pod Autoscaler)
monitors the rate of events and determines whether to scale out or scale in
Heuristics for each trigger type
For example, when you're using an Azure Queue storage trigger, it scales based on the queue length and the age of the oldest queue message.
For the first bullet: A single instance may process more than one message or request at a time though, so there isn't a set limit on number of concurrent executions.