Serverless with Azure Functions

Post on 12-Apr-2017

106 views 0 download

transcript

1www.techtalk.

at

Add Picture

Raoul HolzerAndreas Willich

Serverless with Azure Functions

2

What is a serverless architecture?What is serverless on Azure?What are Azure Functions?What can they do?How do I develop Azure Functions?How the heck can I deploy the stuff?

Questions to be answered

3

Serverless Architecture

4

Who heard about it?

Was your first reaction “Bullshit, there are always server involved”?

Who has an idea what it is?

Serverless architecture

5

Definition from Mike Roberts:

Serverless architectures are internet based systems where the application development does not use the usual server process. Instead they rely solely on a combination of third-party services, client-side logic, and service hosted remote procedure calls.

https://martinfowler.com/bliki/Serverless.html

Serverless architecture

6

By using 3rd party services and sticking them together, I don’t care anymore on which server the code is running.

Serverless architecture

7

Big differences to normal pricing models:

• Classic VM hosting pricing model• X €/Month independent of usage

• Serverless pricing models• A€ for B number of executions• C€ for D usage of resources.

Business driven development

8

Export of data into specific format• Feature that is rarely used• Needs a lot of resources

Classic:Separate VM(s) that provide the functionality

• No influence on performance of the remaining application• If the feature is not used, it costs a lot of money to have the

infrastructure runningServerless:

• Single Function

Business driven development - Example

9

“… the number of active users increased roughly by 50%, but our hosting costs dropped slightly less than 50%. Plus, we replaced what was probably our biggest bottleneck with something that scales without any effort on our side“

Gojko Adzic

https://gojko.net/2017/02/23/serverless-migration-lesson.html

Business driven development

10

Azure’s part

11

• Microsoft Flow• Azure Logic Apps• Azure Automation• Azure Functions

Azure’s parts for Serverless Architecture

12

Azure Functions

13

Which languages can I use?• C#• F#• JavaScript• PHP• Python• Batch• PowerShell• Bash

Most important question first!

14

Through different triggers• Timer schedule• HTTP

• REST• WebHook

• Blob Storage • EventHub• Queue Storage

How gets a Function called?

15

• HTTP Requests• Blobs• Events• Queue Entries• Tables• Push Notifications

What gets in? What gets out?

16

Bindings serve as the basis for all connections to and from a function.

Function Bindings

Type Service Trigger Input OutputSchedule Azure Functions ✔HTTP (REST or webhook) Azure Functions ✔ ✔Blob Storage Azure Storage ✔ ✔ ✔Events Azure Event Hubs ✔ ✔Queues Azure Storage ✔ ✔Tables Azure Storage ✔ ✔Tables Azure Mobile Apps ✔ ✔

No-SQL DB Azure DocumentDB ✔ ✔

Push Notifications Azure Notification Hubs ✔

17

• Scaling• done automatically with magic

• Proxies• One API surface for multiple function app

Which batteries are included?

18

Demo – Creating a function app

19

• Azure Functions are not State-full or State-less• Multiple calls could be in same process

• Up- Scaling needs time• Just because you are having 10 requests at a

moment, you do not get 10 separate processes• Currently not the best performance

Behavior

20

Execution time:€0.000014/GB-s (GigaByte Seconds)1GB used for one second = 1 GB-s512 MB used for 2 seconds = 1 GB-s

Execution count:€0.169 per Million Executions

Free:• 400.000 GB-s• 1 Million Executions

How much does it cost?

21

Development & Deployment of Azure Functions

22

• Flow => included in Office 365, some connections costs• Logic => per Action and App Service Plan • Automation => minute

Prices

23

Programming in Web Browser ?

What if we develop in teams?

Only one code file ?

Real World Development

24

• Azure Functions CLI• https://www.npmjs.com/package/azure-functions-cli

• Visual Studio Tools for Azure Functions• Preview• Visual Studio 2015 Update 3• https://aka.ms/FunctionsVsTools

Tools

Demo

26

• Kudu (Azure Copy Deploy)• Bitbucket• Dropbox• Git local repo• Git external repo• GitHub• Mercurial external repo• OneDrive• Visual Studio Team Services

Deploy Azure Functions in Team Environment

27

• wwwroot• | - host.json• | - FirstFunction• | | - function.json• | | - index.js• | | - node_modules• | | | - ... packages ...• | | - package.json• | - SecondFunction• | | - function.json• | | - run.csx

Folder Hierachy for development

Demo

29

Isolated Azure Functions

30

Function app A

/customer

Function app B

/products

Function app C

Function3/orders

Function1

API proxy endpointsHttpTrigger function endpoints

Key:

/products

/orders

Function2

Azure Functions Proxy

31

{ "proxies": { "proxy1": { "matchCondition": { "methods": [], "route": "/api/{test}" }, "backendUri": "https://contoso.azurewebsites.net/api/{test}" } }}

New file on site root: proxies.json

32

• System• System.Collections.Generic• System.IO• System.Linq• System.Net.Http• System.Threading.Tasks• Microsoft.Azure.WebJobs• Microsoft.Azure.WebJobs.Host.

Automatically imported References

33

• #r "System.Web.Http„• Package management (NuGet, NPM)• Copy to Bin Folder• #load "mylogger.csx" • #load "..\shared\mylogger.csx”

Referencing External Assemblies

34

• Avoid large long running functions• Cross function communication• Write functions to be stateless• Write defensive functions• Don't mix test and production code in the same

function app• Use async code but avoid Task.Result

Best Practices

35

• Thanks to Mark Heath

Example

36

• Azure Functions Source Code:• https://github.com/Azure/azure-webjobs-sdk • https://github.com/Azure/azure-webjobs-sdk-script • https://github.com/projectkudu/AzureFunctionsPortal

• Visualizer Azurehttp://Armviz.io

Links

37

Reading stuff• https://martinfowler.com/articles/serverless.html• https://martinfowler.com/bliki/Serverless.html• https://gojko.net/2016/08/27/serverless.html• https://gojko.net/2017/02/23/serverless-migration-lesso

n.html

Thank you!

40