Serverless / FaaS / Lambda and how it relates to Microservices

60

Transcript of Serverless / FaaS / Lambda and how it relates to Microservices

Page 1: Serverless / FaaS / Lambda and how it relates to Microservices

munz & more

Serverless Architectures & Function as a Service (FaaS) OUGN / March 2017 Dr. Frank Munz

Page 2: Serverless / FaaS / Lambda and how it relates to Microservices

2

Frank Munz

• Founded munz & more in 2007

• 17 years Oracle Middleware,Cloud, and Distributed Computing

• Consulting and High-End Training

• Wrote two Oracle WLS andone Cloud book

Page 3: Serverless / FaaS / Lambda and how it relates to Microservices

Announced by Oracle #OOW2016

Page 4: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless& FaaS

Page 5: Serverless / FaaS / Lambda and how it relates to Microservices

Cloud Computing:

munz & more #5

Page 6: Serverless / FaaS / Lambda and how it relates to Microservices
Page 7: Serverless / FaaS / Lambda and how it relates to Microservices
Page 8: Serverless / FaaS / Lambda and how it relates to Microservices

FaaS / Serverless

Architectures?

munz & more #8

Page 9: Serverless / FaaS / Lambda and how it relates to Microservices

munz & more #9

CloudComputingConcepts

Page 10: Serverless / FaaS / Lambda and how it relates to Microservices

Our IT is an API

A. Cockroft / Netflix

Page 11: Serverless / FaaS / Lambda and how it relates to Microservices

Internet Gateway

Docker Cluster

Computers

Firewall

Access Management

Page 12: Serverless / FaaS / Lambda and how it relates to Microservices

AWS Console: Services

munz & more #12

Page 13: Serverless / FaaS / Lambda and how it relates to Microservices

AWS CLI

munz & more #13

$ aws ec2 describe-regions --output table

Page 14: Serverless / FaaS / Lambda and how it relates to Microservices

SDKs

munz & more #14

Language

bindings

Page 15: Serverless / FaaS / Lambda and how it relates to Microservices

API

munz & more #15

Page 16: Serverless / FaaS / Lambda and how it relates to Microservices

True Elasticity

16

Page 17: Serverless / FaaS / Lambda and how it relates to Microservices

Pay Per Use

You own a massively parallel supercomputer.

Cloud Computing: Use it!

Page 18: Serverless / FaaS / Lambda and how it relates to Microservices

Cloud Computing

API Elasticity Payperuse

FullyProgrammableDataCenter

Page 19: Serverless / FaaS / Lambda and how it relates to Microservices

PaaS

IaaS

FaaS

AmazonEC2OracleBareMetal

AWSBeanstalkOracleACCS

AWSLambdaAzure Functions

GoogleCloudFunctionsOracleTBD

Zeroconfiguration,automaticelasticity.

Truepayperuse.

LaunchConfiguration+Autoscaling Groups

+ScalingEventspay/h/server

Min/Max,AZ,trigger,cooldownperiod

IaaSpricing

API✅Elasticity?

Payperuse?

Page 20: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless

Page 21: Serverless / FaaS / Lambda and how it relates to Microservices

“Serverless” Example

munz & more #21

• S3 = Simple Storage Serviceaka blob storage

• put (key, value)can be (filename, file)

• Offers REST interface

(live?) example: put 2 files to the cloud

Page 22: Serverless / FaaS / Lambda and how it relates to Microservices

S3

munz & more #22

or

http://fmtestweb.s3-website.eu-central-1.amazonaws.com/

#python/boto 3s3.Object('fmtestweb','index.html').put(…)

Page 23: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless Example: S3

munz & more #23

What you get:• Up to 5 TB per object• 14 worldwide regions

(region -> parameter in an API)• 3x replication to 3 different

availability zones (=DC) in a region• Availability 99.99%• Durability 99.999999999% (eleven 9s)

Page 24: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless Example: S3

munz & more #24

Replicatedto3availabilityzones(=DC)

Availability99.99%Durability99.999999999% (eleven9s)

14worldwideregionsregion->APIparameter

Page 25: Serverless / FaaS / Lambda and how it relates to Microservices

The Outage March 2017

munz & more #25

Page 26: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless Example: S3

munz & more #26

• Never provision storage or a DB

• Off instance service = NO virtual server-> serverless

• NO web server

• Resource planning?-> Not for provisioning-> Cost prediction

Page 27: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless Example: S3

munz & more #27

Werner Vogel’s blog is on S3: http://www.allthingsdistributed.com/

Pricing:– Free 5GB for 1 year anyway.

– $0.0245 per GB + $0.0054 per 1,000 requests

Page 28: Serverless / FaaS / Lambda and how it relates to Microservices

S3 is to dataas FaaS is to code

munz & more #28

Page 29: Serverless / FaaS / Lambda and how it relates to Microservices

FaaS

Page 30: Serverless / FaaS / Lambda and how it relates to Microservices

FaaS: Key Characteristics

• Run a function, not servers, not runtime env-> Function as a Service (FaaS)

• Stateless • Triggered by events• Continuous, automated elasticity• True pay per use

munz & more #30

Page 31: Serverless / FaaS / Lambda and how it relates to Microservices

FaaS ImplementationsAmazon Google Microsoft Oracle

Name Lambda CloudFunctions AzureFunctions ?

Year 2014 2016 2016 2016

Status prod alpha beta announced

LanguageSupport

NodeJS 4.3.2,Java8,Python2.7, .Net1.0.1C#,nativeLinux

NodeJS JS,PHP, C#,F#,Python,bash,PowerShell

?

Remarks DeployfromgithuborBitBucket,CLI

Bundle functions,OneDriveandBotServiceintegration

Linked toEventHubCS?

Link https://aws.amazon.com/lambda/

https://azure.microsoft.com/en-us/services/functions/

https://azure.microsoft.com/en-us/services/functions/

https://cloud.oracle.com/home

Page 32: Serverless / FaaS / Lambda and how it relates to Microservices

Edit Code Inline / Upload

munz & more #32

npm node-lambda package for locally running and remotely deploying your node.js

event: event passed to functioncontext: runtime contextcallback: optional return

(or null)

Page 33: Serverless / FaaS / Lambda and how it relates to Microservices

Lambda Tech Details

• Event based with retry + dead letter Q

• Metering in 100 ms

• Chose the memory -> compute power

• Running in containers (not Docker)

• You can use threads and spawn processes

• You can use environment variables

munz & more #33

Page 34: Serverless / FaaS / Lambda and how it relates to Microservices

Lambda: Limits per Function

munz & more #34

Page 35: Serverless / FaaS / Lambda and how it relates to Microservices

Events to Trigger Functions

munz & more #35

EventsfromCloudService- API-Gateway- S3- SNS- Kinesis- Cognito- CloudFormation- CloudWatch

log/events/scheduled- CodeCommit- AppsusingAWSSDK

λVendorlock-in?

alsomultiplesources

Page 36: Serverless / FaaS / Lambda and how it relates to Microservices

Create Lambda

munz & more #36

Page 37: Serverless / FaaS / Lambda and how it relates to Microservices

Example 1: Simple Scenario

munz & more #37

Page 38: Serverless / FaaS / Lambda and how it relates to Microservices

Select Blueprint

munz & more #38

Page 39: Serverless / FaaS / Lambda and how it relates to Microservices

Test Code

munz & more #39

1

2

34

Page 40: Serverless / FaaS / Lambda and how it relates to Microservices

Example 2: API-Gateway

Design and expose API to consumer, including

• Can trigger Lambda• Authentication• Traffic management• Import Swagger definitions• Create JavaScript, Android, iOS SDKs• XML to REST conversion• Uses Cloud Front (CDN) internally

Pricing: #calls + outbound traffic (+cache)

munz & more #40

Page 41: Serverless / FaaS / Lambda and how it relates to Microservices

Image Recognition with Lambda

munz & more #41

https://github.com/awslabs/lambda-refarch-imagerecognition

Page 42: Serverless / FaaS / Lambda and how it relates to Microservices

Example 3:Image Recognition

42

Page 43: Serverless / FaaS / Lambda and how it relates to Microservices

Pay Per Use

Every started request is charged:

• First 1 million req/month are free+ 400,000 GB-seconds of compute time

• Only AWS resource where free tier is free forever.

• Pricing:$0.20 per 1 million req+ $0.00001667 per GBs

munz & more #43

Page 44: Serverless / FaaS / Lambda and how it relates to Microservices

Security

Page 45: Serverless / FaaS / Lambda and how it relates to Microservices

Security

• Not discussed here: Are Clouds Safe?

• Container lifetime -> request = often milli-seconds

• No open ports

• You cannot call Lambdas directly:triggered by events, e.g API-GW or SDK

“Exploit video” by CCC: “Gone in 60ms”

munz & more #45

Page 46: Serverless / FaaS / Lambda and how it relates to Microservices

munz & more #46

https://www.youtube.com/watch?v=YZ058hmLuv0

Page 47: Serverless / FaaS / Lambda and how it relates to Microservices

Microservices

Page 48: Serverless / FaaS / Lambda and how it relates to Microservices

Microservices

Developing a single application as

• a suite of small services• each running in its own process / owns it‘s data• communicating with lightweight mechanisms

(M. Fowler / J. Lewis)

https://martinfowler.com/articles/microservices.html

Page 49: Serverless / FaaS / Lambda and how it relates to Microservices

FaaS = Microservice?

What are other options?

munz & more #49

Page 50: Serverless / FaaS / Lambda and how it relates to Microservices

FaaS vs. K8s Microservices

FaaS fulfills M. Fowler’s microservices definition

munz & more #50

AWS Lambda compared to Docker with Kubernetes

BenefitsofFaaS- serverless- zeroconfig autoscaling- truepayperuse

->higherabstraction

LimitsofFaaS- language/frameworkchoice- resourcelimits- executiontime/size- vendorlock-in->reducedflexibility

Page 51: Serverless / FaaS / Lambda and how it relates to Microservices

munz & more #51

Is𝛌 thenewμ ?

Page 52: Serverless / FaaS / Lambda and how it relates to Microservices

Software

Page 53: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless Framework

Why a framework if your code runs in a “frame”?

• Repeating patterns: IAM, API-GW, S3 bucket etc

• NodeJS, Python, Java

• AWS and Azure

• Generates, deploys, runs Lambda in 3 LOCbased on generated YAML + .py file

munz & more #53https://serverless.com/

Page 54: Serverless / FaaS / Lambda and how it relates to Microservices

Serverless Framework

munz & more #54

Page 55: Serverless / FaaS / Lambda and how it relates to Microservices

AWS Greengrass

Lambda in embedded devices

• Linux 4.4+

• Locally execute Lambda triggered by local event

• Greengrass Core + IoT SDK

munz & more #55

Page 56: Serverless / FaaS / Lambda and how it relates to Microservices

Hardware

Page 57: Serverless / FaaS / Lambda and how it relates to Microservices

- 100TBStorage,256bitTPM- 3x10GB/sNICs- Clusterupto5,

99.999%datadurability- iSCSI,Ethernet,SIMCard- LambdainPython:Greengrass- S3PUT->Lambda- Lambdafunctions

->publicAPI,e.g.AWS- E-InkShippinglabelthatupdates- $300/10days

Snowball Edge (FaaS in a Box):

Page 58: Serverless / FaaS / Lambda and how it relates to Microservices

“Today’s tech entrepreneurs would be out of their minds to build out their own data centers rather than renting capacity from Amazon or another low-cost provider.”

Page 59: Serverless / FaaS / Lambda and how it relates to Microservices

www.munzandmore.com/blog

facebook.com/cloudcomputingbookfacebook.com/weblogicbook

@frankmunz

youtube.com/weblogicbook-> more than 50 web casts

Don’t be

shy J

Page 60: Serverless / FaaS / Lambda and how it relates to Microservices

TL;DR #serverless / #FaaSServerless ∋ FaaS / all major clouds / event driven /stateless / true pay per use /automatic scalability /integrates with other services / cross-cloud frameworksemerge / 𝛌 could be the new µ.

@frankmunz