Slide 1

Slide 1 text

Serverless for (JavaScript) Developers Danilo Poccia @danilop danilop Technical Evangelist

Slide 2

Slide 2 text

Danilo Poccia With AWS Lambda, you write your code and upload it to the AWS cloud. AWS Lambda responds to the events triggered by your application or your users, and auto- matically manages the underlying computer resources for you. Back-end tasks like analyzing a new document or processing requests from a mobile app are easy to implement. Your ap- plication is divided into small functions, leading naturally to a reactive architecture and the adoption of microservices. AWS Lambda in Action is an example-driven tutorial that teaches you how to build applications that use an event-driven approach on the back-end. Starting with an overview of AWS Lambda, the book moves on to show you common examples and patterns that you can use to call Lambda functions from a web page or a mobile app. The second part of the book puts these smaller examples together to build larger applications. By the end, you’ll be ready to create applications that take advantage of the high availability, security, performance, and scalability of AWS. What’s Inside ● Create a simple API ● Create an event-driven media sharing application ● Secure access to your application in the cloud ● Use functions from different clients like web pages or mobile apps ● Connect your application with external services Requires basic knowledge of JavaScript. Some examples are also provided in Python. No AWS experience is assumed. Danilo Poccia is a technical evangelist at Amazon Web Services and a frequent speaker at public events and workshops. To download their free eBook in PDF, ePub, and Kindle formats, owners of this book should visit www.manning.com/books/aws-lambda-in-action $49.99 / Can $57.99 [INCLUDING eBOOK] AWS Lambda IN ACTION SOFTWARE DEVELOPMENT/CLOUD Danilo Poccia M A N N I N G AWS Lambda IN ACTION MANNING “Clear and concise … the code samples are as well structured as the writing.” —From the Foreword by James Governor, RedMonk “A superb guide to an important aspect of AWS.” —Ben Leibert, VillageReach “Step-by-step examples and clear prose make this the go-to book for AWS Lambda!.” —Dan Kacenjar, Wolters Kluwer “Like Lambda itself, this book is easy to follow, concise, and very functional.” —Christopher Haupt, New Relic M A N N I N G SEE INSERT Danilo Poccia FOREWORD BY James Governor Event-driven serverless applications

Slide 3

Slide 3 text

Function

Slide 4

Slide 4 text

greetingsOnDemand

Slide 5

Slide 5 text

Function

Slide 6

Slide 6 text

Function

Slide 7

Slide 7 text

Client Application Function invoke

Slide 8

Slide 8 text

Client Application Function Database Files invoke read/write

Slide 9

Slide 9 text

Client Application Function2 Database Files Function1 Function3 invoke event trigger event trigger read/write

Slide 10

Slide 10 text

Business Logic Client Application Function2 Database Files Function1 Function3 invoke event trigger event trigger read/write

Slide 11

Slide 11 text

Data Persistence Business Logic Client Application Function2 Database Files Function1 Function3 invoke event trigger event trigger read/write

Slide 12

Slide 12 text

Data Persistence Business Logic Client Application Functions Functions Functions Repositories Repositories Repositories API read/write event trigger

Slide 13

Slide 13 text

Data Persistence Business Logic Client Application Functions Functions Functions Repositories Repositories Repositories API read/write event trigger read/write

Slide 14

Slide 14 text

Data Persistence Business Logic Client Application Functions Functions Functions API Gateway Repositories Repositories Repositories API read/write event trigger read/write

Slide 15

Slide 15 text

greetingsAPI

Slide 16

Slide 16 text

How do I start?

Slide 17

Slide 17 text

No Servers to Manage Continuous Scaling Subsecond Metering AWS Lambda

Slide 18

Slide 18 text

1 Million requests per month 400,000 GB-seconds per month Free Tier AWS Lambda

Slide 19

Slide 19 text

https://github.com/awslabs/aws-serverless-auth-reference-app Serverless reference app and backend API, showcasing authentication and authorization patterns using Amazon Cognito, Amazon API Gateway, AWS Lambda, and AWS IAM

Slide 20

Slide 20 text

aws-serverless-auth-reference-app

Slide 21

Slide 21 text

https://serverless.com

Slide 22

Slide 22 text

Building An Infinitely Scalable Online Recording Campaign For David Guetta & UEFA

Slide 23

Slide 23 text

Do I need to rebuild everything?

Slide 24

Slide 24 text

https://github.com/awslabs/aws-serverless-express This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js application framework

Slide 25

Slide 25 text

aws-serverless-express

Slide 26

Slide 26 text

How to go beyond the timeout?

Slide 27

Slide 27 text

function processList(itemList, context) { var item = itemList.shift(); processItem(item, () => { if (itemList.length === 0) { console.log('Finished'); } else if (context.getRemainingTimeInMillis() > TIME_THRESHOLD) { // Process remaning items processList(itemList, context); } else { console.log('Not finished'); // Time is running out, // invoke self asynchrounously to process remaning items invokeSelf(itemList, context); } }); }

Slide 28

Slide 28 text

What about larger apps?

Slide 29

Slide 29 text

https://github.com/awslabs/serverless-application-model

Slide 30

Slide 30 text

> Serverless Continuous Integration and Deployment GitHub Amazon S3 AWS CodeCommit AWS CodeBuild AWS CodeBuild third-party tools AWS CloudFormation Commit Build Test Deploy to Prod AWS CodePipeline + SAM

Slide 31

Slide 31 text

serverless-application-model

Slide 32

Slide 32 text

AWS Step Functions Sequential Steps Branching Steps (Choice of Path) Parallel Steps

Slide 33

Slide 33 text

https://states-language.net/spec.html

Slide 34

Slide 34 text

AWS Step Functions

Slide 35

Slide 35 text

Event-Driven Architecture

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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 Observers Target Action

Slide 38

Slide 38 text

Generate thumbnails Keep another database in sync Process streaming data Services Functions Platform Target Action Kinesis Stream DynamoDB Table S3 Bucket

Slide 39

Slide 39 text

area = length x width

Slide 40

Slide 40 text

area = length x width Procedural Programming “This is a function!”

Slide 41

Slide 41 text

area = length x width Procedural Programming “This is a function!” Reactive Programming “This is data binding!”

Slide 42

Slide 42 text

A B Event-Driven Design For Services ”Service A triggers B" or better ”Service B is caused by A"

Slide 43

Slide 43 text

A B C D E F ? ? What is causing services E and F?

Slide 44

Slide 44 text

A B C D E F New services (E, F) are triggered caused by C

Slide 45

Slide 45 text

A B C D E F It can be cyclic Think of acknowledgements

Slide 46

Slide 46 text

Each service has local visibility A B C D E F

Slide 47

Slide 47 text

What I need to know (input events) 1 A B C D E F

Slide 48

Slide 48 text

What I need to do (internal logic) 2 A B C D E F

Slide 49

Slide 49 text

Who I need to notify (output events) 3 A B C D E F

Slide 50

Slide 50 text

Who I need to notify (output events) What I need to know (input events) What I need to do (internal logic) 1 2 3 B

Slide 51

Slide 51 text

Distributed Data Flow Vs Centralised Workflow

Slide 52

Slide 52 text

Choreography Vs Orchestration

Slide 53

Slide 53 text

Microservices Distributed Systems

Slide 54

Slide 54 text

Monolith Service Service μ μ μ space (distribution, mobility) time (concurrency, latency) μ μ μ μ “Distributed in Time and Space” [Jonas Bonér]

Slide 55

Slide 55 text

“…a diagram of two microservices and their shared database” Data should drive the boundaries

Slide 56

Slide 56 text

A C I D tomic onsistent solated urable

Slide 57

Slide 57 text

A C I D tomic onsistent solated urable A C I D ssociative ommutative dempotent istributed ACID 2.0

Slide 58

Slide 58 text

Scale from Prototype to Production

Slide 59

Slide 59 text

Responsive Resilient Elastic Message Driven The Reactive Manifesto

Slide 60

Slide 60 text

Asynchronous communication is not enforced by serverless architectures Responsive Resilient Elastic Message Driven The Reactive Manifesto

Slide 61

Slide 61 text

Lambda Everywhere

Slide 62

Slide 62 text

AWS Greengrass

Slide 63

Slide 63 text

AWS Snowball Edge

Slide 64

Slide 64 text

AWS Snowball Edge

Slide 65

Slide 65 text

AWS Snowmobile

Slide 66

Slide 66 text

Lambda@Edge

Slide 67

Slide 67 text

Build Apps With Services, Not Servers

Slide 68

Slide 68 text

https://aws.amazon.com/lambda https://github.com/awslabs/aws-serverless-auth-reference-app https://github.com/awslabs/aws-serverless-express https://serverless.com https://github.com/awslabs/serverless-application-model https://states-language.net/spec.html https://github.com/danilop/AWS_Lambda_in_Action For Your Reference

Slide 69

Slide 69 text

Thank You! Danilo Poccia @danilop danilop Technical Evangelist