Function as a Service (FaaS) aka ServerlessComputingdelara/courses/ece1779/handouts/lambda/L… ·...

Preview:

Citation preview

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

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

3

5

Lambda Application Architecture

5

6

1st Lambda Function

6

4

7

1st Lambda Function

7

8

1st Lambda Function

8

5

9

1st Lambda Function

9

10

1st Lambda Function

10

6

11

1st Lambda Function

11

12

Lambda Function Testing Arguments

12

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

8

15

Reacting to S3 Events

15

16

Reacting to S3 Events

16

9

17

Reacting to S3 Events

17

18

Reacting to S3 Events

18

10

19

Reacting to S3 Events

19

20

Reacting to S3 Events

20

11

21

Reacting to S3 Events

21

22

Reacting to S3 Events

22

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

13

25

Function as Web API

25

26

Function as Web API

26

14

27

Function as Web API

27

28

Function as Web API

28

15

29

Function as Web API

29

30

Function as Web API

30

16

31

Function as Web API

31

32

Function as Web API

32

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

18

35

Zappa

• zappa_settings.json

• Deploy application to AWS Lambda > zappa deploy dev

35

Recommended