Top Banner
Building Event-Driven Serverless Applications Danilo Poccia Technical Evangelist @danilop danilop
54

Building Event-Driven Serverless Applications

Apr 15, 2017

Download

Software

Danilo Poccia
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building Event-Driven Serverless Applications

Building Event-DrivenServerless Applications

Danilo PocciaTechnical Evangelist

@danilopdanilop

Page 2: Building Event-Driven Serverless Applications

Virtual Machines

Page 3: Building Event-Driven Serverless Applications

Virtual Machines Containers

Page 4: Building Event-Driven Serverless Applications

Virtual Machines Containers Functions

Page 5: Building Event-Driven Serverless Applications

Event-Driven in the Front End

Page 6: Building Event-Driven Serverless Applications

Name

Email

Create New User

Submit

Check the “Name” syntax is right (only letters and spaces)

Check the “Email” syntax is right ([email protected])

Create the new user using provided Name and Email

User Interface Actions

Page 7: Building Event-Driven Serverless Applications

Name

Email

Create New User

Submit

Check the “Name” syntax is right (only letters and spaces)

Check the “Email” syntax is right ([email protected])

Create the new user using provided Name and Email

User Interface ActionsObservers

Target Action

Page 8: Building Event-Driven Serverless Applications

What about the Back End ?

Page 9: Building Event-Driven Serverless Applications

! Users

Page 10: Building Event-Driven Serverless Applications

Internet

! Users

Page 11: Building Event-Driven Serverless Applications

Back End Logic

Internet

! Users

Page 12: Building Event-Driven Serverless Applications

Back End Data

Back End Logic

Internet

! Users

Page 13: Building Event-Driven Serverless Applications

Back End Data

Application Back End

Back End Logic

Internet

! Users

Page 14: Building Event-Driven Serverless Applications

Application Back End" Web Browsers

Back End Data

Back End Logic

Page 15: Building Event-Driven Serverless Applications

Application Back End" Web Browsers

# Mobile Apps Back End

Data

Back End Logic

Page 16: Building Event-Driven Serverless Applications

Application Back End" Web Browsers

# Mobile Apps

$ IoT Devices

Back End Data

Back End Logic

Page 17: Building Event-Driven Serverless Applications

Application Back End" Web Browsers

# Mobile Apps

$ IoT Devices

% Other Services

Back End Data

Back End Logic

Page 18: Building Event-Driven Serverless Applications

Application Back End

Files

Databases

" Web Browsers

# Mobile Apps

$ IoT Devices

% Other Services

Back End Logic

Page 19: Building Event-Driven Serverless Applications

HTML, CSS, JavaScript & Multimedia Content

API Calls

Application Back End" Web Browsers

# Mobile Apps

$ IoT Devices

% Other Services

Files

Databases

Back End Logic

Page 20: Building Event-Driven Serverless Applications

API Calls

Application Back End

HTML, CSS, JavaScript & Multimedia Content

" Web Browsers

(JavaScript)

# Mobile Apps

$ IoT Devices

% Other Services

By using JavaScript, Web Browsers can behave

like the other clients, such as Mobile Apps

or IoT Devices

Files

Databases

Back End Logic

Page 21: Building Event-Driven Serverless Applications

API Calls

Application Back End

HTML, CSS, JavaScript & Multimedia Content

" Web Browsers

(JavaScript)

# Mobile Apps

$ IoT Devices

% Other Services

Files

Databases

Back End Logic

Page 22: Building Event-Driven Serverless Applications

Client Application

API Calls

Application Back End

HTML, CSS, JavaScript & Multimedia Content

The Client Application can be a Web Browser,

a Mobile App, an IoT Device,

or another Service

We can now decouple the back end implementation

from the device used by our users

Files

Databases

Back End Logic

Page 23: Building Event-Driven Serverless Applications

Client Application

API Calls

Application Back End

HTML, CSS, JavaScript & Multimedia Content

The Client Application can be a Web Browser,

a Mobile App, an IoT Device,

or another Service

Files

Databases

Back End Logic

Page 24: Building Event-Driven Serverless Applications

Functions as your API

Page 25: Building Event-Driven Serverless Applications

Context

Function

Event AWS Lambda

Result

RequestResponse Function

Invocation

Lambda API Call

AWS Lambda Functions Synchronous Invocations

Page 26: Building Event-Driven Serverless Applications

Context

Function

Event AWS Lambda

Event Function

Invocation

Lambda API Call

AWS Lambda Functions Asynchronous Invocations

Page 27: Building Event-Driven Serverless Applications

ContextContextResource

ContextContextResource

Context

Function

Event AWS Lambda Managed by AWS

Not managed by AWS

Result (Optional)

Function Invocation

Resources can be files, records

in a DB, etc.

Lambda API Call

Functions can Modify Resources

Page 28: Building Event-Driven Serverless Applications

Events (Context)

Events (Context)

Generated by AWS

Not generated by AWS

ContextContextResource

ContextContextResource

Context

Function

Event AWS Lambda Managed by AWS

Not managed by AWS

Result (Optional)

Function Invocation

Lambda API Call

Resources can Generate more Events

Page 29: Building Event-Driven Serverless Applications

Events (Context)

Events (Context)

Generated by AWS

Not generated by AWS

ContextContextResource

ContextContextResource

AWS Lambda Managed by AWS

Not managed by AWS

Direct Use of Resource

For example, a file is uploaded

or something is written in a database

AWS Lambda

Function 2

Function 3

Function 1

Events can Trigger more Functions

Page 30: Building Event-Driven Serverless Applications

Sample Event-Driven Serverless Media-Sharing Application

Page 31: Building Event-Driven Serverless Applications

Client Application

Event-driven Backend&

User

Page 32: Building Event-Driven Serverless Applications

Client Application

Get Content Index

Get Content

Upload Content with Metadata

Update Content Metadata

Get Content Metadata

& User

Page 33: Building Event-Driven Serverless Applications

Client Application

Get Content Index

Get Content

Upload Content with Metadata

Update Content Metadata

Get Content Metadata

AWS Lambda

& User

Page 34: Building Event-Driven Serverless Applications

Client Application

Get Content Index

Get Content

Upload Content with Metadata

Update Content Metadata

Get Content Metadata

Files (Multimedia)

Database

AWS Lambda

& User

Resources

Page 35: Building Event-Driven Serverless Applications

Client Application

Get Content Index

Get Content and Thumbnails

Upload Content with Metadata

Update Content Metadata

Get Content Metadata

Files (Multimedia)

Database

Build Thumbnails

Update Content Index

Extract and Update Metadata

Event: new or

updated file

Event: new or updated

content metadata

AWS Lambda

& User

Resources

Page 36: Building Event-Driven Serverless Applications

Get Content Index

Get Content and Thumbnails

Upload Content with Metadata

Update Content Metadata

Get Content Metadata

Files (Multimedia)

Database

Build Thumbnails

Update Content Index

Extract and Update Metadata

& User

# Mobile

App

Page 37: Building Event-Driven Serverless Applications

Get Content Index

Get Content and Thumbnails

Upload Content with Metadata

Update Content Metadata

Get Content Metadata

Files (Multimedia)

Database

Build Thumbnails

Update Content Index

Extract and Update Metadata

& User

" Web Browsers

(JavaScript)

Page 38: Building Event-Driven Serverless Applications

Calling Functions from the Client

Page 39: Building Event-Driven Serverless Applications

Client Application

AWS Lambda Function

AWS Lambda Invoke API

& User

Calling Lambda Functions Directly

Page 40: Building Event-Driven Serverless Applications

Client Application

AWS Lambda Function

AWS Lambda Invoke API

Get Temporary AWS Credentials Amazon

Cognito

& User

Getting AWS Credentials from Amazon Cognito

Page 41: Building Event-Driven Serverless Applications

Client Application

AWS Lambda Function

Amazon Cognito

Amazon API Gateway

Get Temporary AWS Credentials

Web API Modeling, Caching, Throttling, Logging, CDN, etc.

& User

Exposing Functions as Web API

Page 42: Building Event-Driven Serverless Applications

Client Application

AWS Lambda Function

Amazon API Gateway

Web API Modeling, Caching, Throttling, Logging, CDN, etc.

& User

Exposing Functions as Public Web API

Page 43: Building Event-Driven Serverless Applications

https://some.domain/stage/resource1/resource2/…/resourceN

GETPOSTPUTDELETEHEADPATCHOPTIONS

Unique domain that you can customize

API stage, for example prod, test, dev, or v0, v1, …

Resources as part of the URL

HTTP verb used when

accessing the URL

function1function2function3function1function2

function3function1

Function to execute

Web API to Lambda Functions Integration

Page 44: Building Event-Driven Serverless Applications

Web API to Lambda Functions Mapping

Resource + HTTP Verb ➔ Method

Page 45: Building Event-Driven Serverless Applications

Web API to Lambda Functions Mapping

Resource + HTTP Verb ➔ Method

/books + GET ➔ GetAllBooks

Page 46: Building Event-Driven Serverless Applications

Web API to Lambda Functions Mapping

Resource + HTTP Verb ➔ Method

/books + GET ➔ GetAllBooks

/books + POST ➔ CreateNewBook

Page 47: Building Event-Driven Serverless Applications

Web API to Lambda Functions Mapping

Resource + HTTP Verb ➔ Method

/books + GET ➔ GetAllBooks

/books + POST ➔ CreateNewBook

/books/{id} + GET ➔ GetBookById

/books/{id} + PUT ➔ CreateOrUpdateBookById

/books/{id} + DELETE ➔ DeleteBookById

Page 48: Building Event-Driven Serverless Applications

Best Practices

Page 49: Building Event-Driven Serverless Applications
Page 50: Building Event-Driven Serverless Applications

Distributed Systems

Page 51: Building Event-Driven Serverless Applications

Distribute the Logic React to Changes

Page 52: Building Event-Driven Serverless Applications

Preserve Independent Deployment

Of Functions

Page 53: Building Event-Driven Serverless Applications

<demo>...

</demo>

Page 54: Building Event-Driven Serverless Applications

Building Event-DrivenServerless Applications

Danilo PocciaTechnical Evangelist

@danilopdanilop