18
1 © 2010 VMware Inc. All rights reserved Function as a Service (FaaS) aka Serverless Computing AWS Lambda in Action Danilo Poccia Manning 1 2 Function as a Service (FaaS) § Cloud provider Manages infrastructure Manages software stack (OS, runtime) Handles provisioning Availability Scalability § Developer Implements application as set of functions Functions run when certain events are triggered Web request File upload Alarm Database update § Examples: AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2

Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

1

© 2010 VMware Inc. All rights reserved

Function as a Service (FaaS)aka

Serverless Computing

AWS Lambda in ActionDanilo PocciaManning

1

2

Function as a Service (FaaS)

§ Cloud provider • Manages infrastructure

• Manages software stack (OS, runtime)

• Handles provisioning

• Availability

• Scalability

§ Developer• Implements application as set of functions

• Functions run when certain events are triggered

• Web request

• File upload

• Alarm

• Database update

§ Examples:• AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions

2

Page 2: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

2

3

Lambda Execution Environment

§ Function runs inside an operating system container• Single OS runs multiple containers• Isolation ensures that only processes inside container are visible• Has its own file system /tmp

§ Runtimes: C#, Node.js, Java, Python

§ A container handles a single function/event at a time

§ Concurrent execution by container replication

§ Containers may be reused for subsequent function executions

§ Containers may be terminated at any time• Stateless• Store all persistent state outside of container

3

4

Lambda Invocation Modalities

§ Synchronous (RequestResponse)

§ Asynchronous (Event)

4

Page 3: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

3

5

Lambda Application Architecture

5

6

1st Lambda Function

6

Page 4: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

4

7

1st Lambda Function

7

8

1st Lambda Function

8

Page 5: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

5

9

1st Lambda Function

9

10

1st Lambda Function

10

Page 6: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

6

11

1st Lambda Function

11

12

Lambda Function Testing Arguments

12

Page 7: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

7

13

Lambda Function Testing

13

14

Lambda Command Line Interface (CLI)

§ Download from http://aws.amazon.com/cli

§ Configure credentials

Create access key on AWS Console

> aws configure

§ Call function

> aws lambda list-functions

> aws lambda invoke --function-name helloWorld --payload '{}' output.txt

> aws lambda invoke --function-name helloWorld --payload '{"name":"Eyal"}' output.txt

14

Page 8: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

8

15

Reacting to S3 Events

15

16

Reacting to S3 Events

16

Page 9: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

9

17

Reacting to S3 Events

17

18

Reacting to S3 Events

18

Page 10: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

10

19

Reacting to S3 Events

19

20

Reacting to S3 Events

20

Page 11: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

11

21

Reacting to S3 Events

21

22

Reacting to S3 Events

22

Page 12: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

12

23

Function as Web API

§ Amazon API Gateway can be integrated with Lambda§ Turn http request into Lambda events§ Maps each Lambda Event into a URL endpoint

23

24

Function as Web API

24

Page 13: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

13

25

Function as Web API

25

26

Function as Web API

26

Page 14: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

14

27

Function as Web API

27

28

Function as Web API

28

Page 15: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

15

29

Function as Web API

29

30

Function as Web API

30

Page 16: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

16

31

Function as Web API

31

32

Function as Web API

32

Page 17: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

17

33

Function as Web API

33

34

Zappa

• Deploy Python WSGI applications on AWS Lambda + API Gateway. • https://github.com/Miserlou/Zappa

• Steps:• Install and configure AWS CLI• Create flask directory structure• Create a python virtual environment:

> virtualenv -p python3.6 venv> source venv/bin/activate

• Install flask> pip install flask

• Install zappa> pip install zappa> zappa init

34

Page 18: Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… · •AWS Lambda, Google Cloud Functions, IBM OpenWhisk, MSFT Azure Functions 2. 2

18

35

Zappa

• zappa_settings.json

• Deploy application to AWS Lambda > zappa deploy dev

35