59
Serverless in Action CodeStock April 13, 2019 Chad Green

Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in ActionCodeStock

April 13, 2019

Chad Green

Page 2: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Who is Chad Green

• Director of Software Development at ScholarRx

• Community Involvement

• Code PaLOUsa Conference Chair

• Louisville .NET Meetup Organizer

• Louisville Tech Leaders Meetup Co-Organizer

• Louisville Tech Ladies Committee Member

• Contact Information

[email protected]

chadgreen.com

ChadGreen

ChadwickEGreen

Page 3: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Agenda

3

• What is Serverless Computing

• Functions as a Service

• Serverless Options

• Azure Functions Overview

• Azure Functions in Action

• Pricing

• Best Practices

Page 4: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

What is Serverless Computing

Serverless in Action

Page 5: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

The evolution of application platforms

5

Which packages should

be on my server?

How do I deploy new

code to my servers?How can I increase

server utilization?

How often should I

patch my servers?

What size of servers

should I buy?

Who has physical

access to my servers?

It takes how long to

provision a new server?

On-Premises

Page 6: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

The evolution of application platforms

6

What is the right size of servers for my business needs?

How can I increase server utilization?

How many servers do I need?

How can I scale my application?

How do I deploy new code to my server?

Which Operating System should I use?

Who monitors my application?

How often should I patch my servers?

How often should I backup my server?

Which packages should be on my server?

IaaSOn-Premises

Page 7: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

The evolution of application platforms

7

What is the right size of servers for my business needs?

How can I increase server utilization?

How many servers do I need?

How can I scale my application?

PaaSIaaSOn-Premises

Page 8: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

The evolution of application platforms

8

The platform for next generation applications

PaaSIaaSOn-Premises Serverless

Page 9: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

What is Serverless?

9

Abstraction of Servers Event-Driven/Instant Scale Micro-Billing

Page 10: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Benefits of Serverless

10

Reduced DevOps Faster Time to MarketManage apps not

servers

Page 11: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Challenges of Serverless Architecture

11

ComplexityOrganizational

Support

No Runtime

Optimization

Page 12: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Function as a Service

Serverless in Action

Page 13: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Serverless is more than just one thing

13

• Applications that significantly or fully

depend on services (in the cloud) to

manage server-side logic and state

Backend as a Service

(BaaS)

Functions as a Services (FaaS)

• Application run in stateless compute

containers that are event-triggered,

ephemeral, and fully managed by a 3rd

party

Page 14: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Function Scale

14

Monolith

Microservice

Microservice

Microservice

Microservice

Function

Function

Function

Function

Function

Function

Function

Function

Function

Function

Function

Nano Services

Page 15: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

FaaS is at the center of serverless

15

Single responsibilityFunctions are single-purposed, reusable pieces of code that process an input and return a result

Short livedFunctions don’t stick around when finished executing, freeing up resources for further executions

Event driven & scalableFunctions respond to predefined events, and are instantly replicated as many times as needed

StatelessFunctions don’t hold any persistent state and don’t rely on the state of any other processes

Functions-as-a-Service programming model use functions to achieve true serverless compute

Page 16: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless Options

Serverless in Action

Page 17: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Market Landscape

17

AWS

LambdaGoogle

Cloud Functions

IBM

Cloud

Functions

Auth0

WebTask

Azure

Run code without thinking about servers. Pay only for

the compute time you consume.Event-driven serverless compute platform

Execute code on demand in a highly scalable serverless

environmentAll you need is codeYour vision. Your cloud.

Page 18: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Azure Serverless Offerings

18

Event GridManage all events that

can trigger code or logic

Logic AppsDesign workflows and

orchestrate processes

FunctionsExecute your code based

on events you specify

Storage Security IoT Analytics IntelligenceDatabase

Page 19: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Azure Functions

Serverless in Action

Events + dataCode

Page 20: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Features of Azure Functions

20

• Choice of language

Batch

Page 21: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Features of Azure Functions

21

• Choice of language

• Pay-per-use pricing model

21

Batch

Page 22: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Features of Azure Functions

22

• Choice of language

• Pay-per-use pricing model

• Bring your own dependencies

Page 23: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Features of Azure Functions

23

• Choice of language

• Pay-per-use pricing model

• Bring your own dependencies

• Integrated security

Page 24: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Features of Azure Functions

24

• Choice of language

• Pay-per-use pricing model

• Bring your own dependencies

• Integrated security

• Simplified integration

Page 25: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Features of Azure Functions

25

• Choice of language

• Pay-per-use pricing model

• Bring your own dependencies

• Integrated security

• Simplified integration

• Flexible development

Page 26: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Features of Azure Functions

26

• Choice of language

• Pay-per-use pricing model

• Bring your own dependencies

• Integrated security

• Simplified integration

• Flexible development

• Open-source

Page 27: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Triggers and Bindings

27

TypeBlob Storage

Cosmos DB

Event Grid

Event Hubs

External File

External Table

HTTP

Microsoft Graph

OneDrive FilesMicrosoft Graph

Outlook email

Microsoft Graph

Auth tokens

Mobile Apps

Notification Hubs

Queue Storage

SendGrid

Service Bus

Table Storage

Timer

Twilio

Webhooks

1.x

Microsoft Graph

Excel tables

2.x Trigger

Microsoft Graph

Events

Input Output

Page 28: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Develop How You Want

28

• Azure Portal

• Quickly get started without having to install anything

else

• Visual Studio 2017

• First class C# development experience

• Visual Studio Code

• First class Node.js development experience

• Edit any function project generated via CLI

• Azure Functions Core Tools (CLI)

• Build any kind of function and edit in IDE of your

choice

Page 29: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Runtime Versions

29

• .NET Framework 4.6

Runtime 1.x Runtime 2.x

• .NET Core 2.0

• Cross Platform

• Language Extensions

• Java

• Binding Extensions

• Microsoft Graph

• Durable Functions

Page 30: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Runtime Version Languages

30

Language

C#

JavaScript

F#

Java

Python

TypeScript

PHP

Batch (.cmd, .bat)

Bash

PowerShell

1.x

GA (.NET Framework 4.7)

GA (Node 6)

GA(.NET Framework 4.7)

N/A

Experimental

Experimental

Experimental

Experimental

Experimental

Experimental

2.x

GA (.NET Core 2)

GA (Node 8 & 10)

GA (.NET Core 2)

Preview (Java 8)

Preview (Python 3.6)

Supported through transpiling to JavaScript

N/A

N/A

N/A

N/A

Page 31: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Consumption Plan

31

• Pay for what you use without the need to reserve compute

resources.

• Function Apps are assigned to compute processing instances

that are scaled dynamically by the platform.

• Functions can have multiple parallel executions minimizing the

total time needed to process requests.

• Cost is driven by the number of executions and by accounting

for memory size used and total execution time across all

functions in a Function App as measured in gigabyte-seconds.

Selection guidance

• Good option if your functions run at elastic scale with

potentially intermittent executions.

Page 32: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

App Service Plan

32

• Function Apps run on dedicated VMs, just like Web Apps work

today

• Dedicated VMs are allocated to your apps and they are always

available whether code is being actively executed or not.

Selection guidance

• Good option if you have existing, under-utilized VMs that are

already running other code

• Good option if you expect to run functions continuously or

almost continuously

Page 33: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Premium Plan

33

Page 34: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Ways to Run Functions

34

App Service

PlanFree, Basic,

Standard, Premium

All the

advantages of

Functions with the

SLA and ‘always

on’ feature of an

App Service Plan

ConsumptionServerless

Pay only for what

you use! Metering

is per execution

and per Gb

second.

App Service

EnvironmentNetwork Isolation

Your own

dedicated cloud

environment with

network isolation

for apps, higher

scale, and the

ability to connect

securely to local

vNets.

Azure StackOn Premises

Leverage cloud

innovations in on-

premises

infrastructure.

Azure Stack

brings the power

of Azure to your

data centers.

Azure Functions

RuntimeFunctions on your

Server

Run your Azure

Functions on our

local server

(without the rest

of Azure)

Azure IoT EdgeOn Devices

Run on IoT

Devices by

deploying custom

modules.

Page 35: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Azure Functions in Action

Serverless in Action

Page 36: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Demo: Create an Azure

Function from the Portal

Page 37: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Demo: Create an Azure

Function from Visual Studio

Page 38: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven
Page 39: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven
Page 40: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Deployment and Monitoring

42

• Visual Studio

• Functions CLI

• Azure DevOps

• Azure Resource Manager

• Maven / Jenkins

Deployment Options Monitoring Options

• Azure App Insights

• Function Logs

• Azure Monitor (preview)

Page 41: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Demo: Monitoring a Rapidly

Scaling Function

Page 42: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Testing Your Functions

44

• Recommended Way

• Abstract logic away from the Function and test that abstraction

• But I really need (want) to test the actual Function

• Within test project, you will need to create a class that implements the

ILogger which will be passed into the Functions

Page 43: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Demo: Testing Your Azure

Functions

Page 44: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Pricing

Serverless in Action

Page 45: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Pricing – General Information

47

• No upfront cost

• No termination fees

• Pay only for what you use

Page 46: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Consumption Plan Pricing

48

• Gigabyte-second (GB-s) – Combination of memory size and execution time

• Executions – Each time a function is executed

Meter Price Free Grant

Execution Time $0.000016 per Gb-s 400,000 GB-s

Executions $0.20 per million executions 1 million executions

Pricing Example• Execution Time

• 3 million executions x 1 second per execution = 3 million seconds

• Resource consumption of 512-Mb → 1.5 million GB-s

• 1.5 million GB-s minus grant of 400,000 Gb-s = 1.1 million Gb-s

• Execution Total = $17.60

• Executions

• 3 million executions minus grant of 1 million executions = 2 million executions

• 2 million transactions at 20 cents per million = $0.40

• Grand Total: $18.00

Page 47: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Best Practices

Serverless in Action

Page 48: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Function Timeouts

50

• Default timeout of 5 minutes

• Maximum timeout of 10 minutes

• For longer running functions use the App Service

Plan and/or Durable Functions

Page 49: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

The absolute minimum best practices

51

• Functions should do one thing

• Functions should be idempotent

• Functions should finish as quickly as possible

Page 50: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

General Best Practices

52

• Avoid long running functions

Page 51: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

General Best Practices

53

• Avoid long running functions

• Cross function communication

Page 52: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

General Best Practices

54

• Avoid long running functions

• Cross function communication

• Write functions to be stateless

Page 53: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

General Best Practices

55

• Avoid long running functions

• Cross function communication

• Write functions to be stateless

• Write defensive functions

Page 54: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Scalability Best Practices

56

• Do not mix test and production code in the same

function app

Page 55: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Scalability Best Practices

57

• Do not mix test and production code in the same

function app

• Use async code but avoid blocking calls

Page 56: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Scalability Best Practices

58

• Do not mix test and production code in the same

function app

• Use async code but avoid blocking calls

• Receive messages in batch whenever possible

Page 57: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

Scalability Best Practices

59

• Do not mix test and production code in the same

function app

• Use async code but avoid blocking calls

• Receive messages in batch whenever possible

• Configure host behaviors to better handle

concurrency

Page 58: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Serverless in Action

How to get started

60

• 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

Page 59: Chad Green Serverless in Action · 2019. 5. 16. · IBM Cloud Functions Auth0 WebTask Azure Run code without thinking about servers. Pay only for the compute time you consume. Event-driven

Questions

[email protected]

chadgreen.com

ChadGreen

ChadwickEGreen

Slides: bit.ly/CM19AzureFunctions