Azure Functions offer server-less cloud services and are the next evolution in distributed computing and hosting after containers. Join this session to learn how to develop Azure Functions using C# and .NET, and how to test, build and deploy to Azure. We will cover .NET programming details, architecture, internals and hosting. Also, you will learn how to set up a local development environment to build and host locally. After this session you are ready to design and create state of the art Azure Functions using .NET
6. 6
Event-driven
Responds to external triggers
Instant scaling
Abstraction of server infrastructure
Scales when needed
Pay by consumption
Charged by sub-second units of compute
11. 11
Scripts
Azure Portal or Visual Studio Code
.NET with C#
Visual Studio 2017
Instant feedback and testing
Less control
Azure tooling generates metadata files
Integrates with
source control
1 2
Achieve higher code quality
Compilation and code analysis
Unit testing
Combine in
CI/CD pipelines
14. 14
Function apps
• Hosted as Azure App Service
• JSON based configuration
• Running (multiple) functions
Trigger starts execution
Bindings for
input and output
Zero or more possible
Triggers and bindings can vary
per function
19. 19
[FunctionName("HelloWorldFunction")]
public static HttpResponseMessage Run(
[HttpTrigger] HttpRequestMessage req,
TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
return req.CreateResponse(HttpStatusCode.OK, "Hello, World!");
}
Defines what this function
is triggered by
20. 20
[FunctionName("ImageAnalyzer")]
[return: Queue("AnalysisResults", Connection="…")]
public static string Run(
[QueueTrigger("ImagesToAnalyze", Connection="…")] string imageName,
[Blob("images/{queueTrigger}",
FileAccess.Read,
Connection = "…")] Stream blob, TraceWriter log) {
return ...;
}
Connection property refers
to value from application
settings
Attribute values can refer to
trigger metadata with { }
26. 26
Blob and queue
• Simply supply message
content
• Depends on input type
(string, byte[] or
POCO class)
HttpRequestMessage
• Able to be constructed
as dummy object
• Set properties for Body
and Headers
• Similar for
HttpResponse(Message)
TraceWriter
• Inherit and override
Write method for mock
• Alternatively use ILogger
provided through DI
29. 29
Consumption-based
Scaling as needed
Might require time to provide compute instances
App Service plan
Available scale
Not so much server-less
Easy to combine with PaaS
Azure Functions Runtime
Local installation of hosts
Connected via SQL Server database
Infrastructure operations
Not so much server-less
Azure On-premises
36. 36
Single responsibility principle
Do one thing focussed
Finish as quickly as possible
Avoid long running functions
Stateless, idempotent and defensive
Cross function communication
Messaging: Storage Queues (small <64 KB) or Service Bus (<256 KB)
Service Bus topics for message filtering
Event Hub for high volume messaging
Blob trigger metadata:
BlobTrigger. Type string. The triggering blob path
Uri. Type System.Uri. The blob's URI for the primary location.
Properties. Type Microsoft.WindowsAzure.Storage.Blob.BlobProperties. The blob's system properties.
Metadata. Type IDictionary<string,string>. The user-defined metadata for the blob.
HttpRequestMessage request = new HttpRequestMessage();
request.Content = new StringContent(“{‘name’:’Alex’}, System.Text.Encoding.UTF8, “application/json”);
request.SetConfiguration(new HttpConfiguration());
var results = await DemoFunction.Run(request, new FakeTraceWriter());
(await result.Content.ReadAsStringAsync()).Should…
<GenerateBindingRedirectsOutputType>true
<AutoGenerateBindingRedirects>true
func azure functionapp publish <FunctionAppName>
https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring#write-logs-in-c-functions
requests
| where timestamp > ago(30m)
| summarize count() by cloud_RoleInstance, bin(timestamp, 1m)
| render timechart
az functionapp config appsettings set --name <function_app> \ --resource-group myResourceGroup \ --settings FUNCTIONS_EXTENSION_VERSION=beta