introduction to serverless

32
Introduction to Serverless

Upload: nikolaus-graf

Post on 08-Feb-2017

364 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Introduction to Serverless

Introduction to Serverless

Page 2: Introduction to Serverless

What is Serverless?• Serverless Book

• Serverless Conference

• Serverless Framework

• Serverless Inc.

• Serverless Architectures

• Serverless Application Model

Page 3: Introduction to Serverless
Page 4: Introduction to Serverless
Page 5: Introduction to Serverless
Page 6: Introduction to Serverless
Page 7: Introduction to Serverless

Mike Roberts

“Serverless architectures refer to applications that significantly depend on third-party services (knows as Backend as a Service or

"BaaS") or on custom code that's run in ephemeral containers (Function as a Service or "FaaS"), the best known vendor host of

which currently is AWS Lambda. By using these …”

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

Page 8: Introduction to Serverless

Function as a unit of application logic

Page 9: Introduction to Serverless

How does it work?

• New instances based on invocation demand

• Events trigger a function

Page 10: Introduction to Serverless

Check if an instance is running

Yes No

Handle the Request

Stop the Process(stop the instance if idle to long)

Start an instanceActivate the Process

Page 11: Introduction to Serverless
Page 12: Introduction to Serverless
Page 13: Introduction to Serverless

Isn’t that limiting?

Yes! 🙃

Page 14: Introduction to Serverless
Page 15: Introduction to Serverless

Benefits

• 📈 Auto scaling

• 💵 Pay per execution

• 🎪 Event Driven

• 🗝 Security

Page 16: Introduction to Serverless

Common Use Cases

• 🕸 Web Applications

• 📱 Mobile & IoT Backends

• 💹 Data Processing

• 🤖 Chatbots

Page 17: Introduction to Serverless

Providers• AWS Lambda

• Google Cloud Functions

• Microsoft Functions

• IBM Openwhisk

• Auth0 Webtasks

• IronIO IronFunctions

• many more …

Page 18: Introduction to Serverless

Numbers

• Thomson Reuter processes 4000 req/sec

• Finra processes half a trillion validations of stock trades daily

• Vevo can handle spikes of 80x normal traffic

Page 19: Introduction to Serverless

Challenges• Monitoring

• Cold starts

• Development flow

• Application architecture

• Service Discovery

• Service Communication

Page 20: Introduction to Serverless

Deployment Options

• User Interface

• API calls (Serverless Framework v0, Claudia, Zappa, Apex)

• CloudFormation (Serverless Framework v1, SAM)

Page 21: Introduction to Serverless

Deploy via the UI

Page 22: Introduction to Serverless

Deploy via the APIvar params = { Code: {}, Description: "", FunctionName: "MyFunction", Handler: "souce_file.handler_name", MemorySize: 128, Publish: true, Role: "arn:aws:iam::123456789012:role/service-role/role-name", Runtime: "nodejs4.3", Timeout: 15, VpcConfig: {}};lambda.createFunction(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data);});

Page 23: Introduction to Serverless

Deploy via CloudFormation

Page 24: Introduction to Serverless

Deploy via Serverless Framework# serverless.ymlservice: serverless-simple-http-endpoint

frameworkVersion: ">=1.1.0 <2.0.0"

provider: name: aws runtime: nodejs4.3

functions: currentTime: handler: handler.endpoint events: - http: path: ping method: get

Page 25: Introduction to Serverless

// handler.jsmodule.exports.endpoint = (event, context, callback) => { const time = new Date().toTimeString(); const response = { statusCode: 200, body: JSON.stringify({ message: `Hello, the current time is ${time}.`, }), };

callback(null, response);};

Page 26: Introduction to Serverless
Page 27: Introduction to Serverless
Page 28: Introduction to Serverless

service: scheduled-cron-example

provider: name: aws runtime: nodejs4.3

functions: cron: handler: handler.run events: # Invoke Lambda function every minute - schedule: rate(1 minute) secondCron: handler: handler.run events: # Invoke Lambda function every 2nd minute from Mon-Fri - schedule: cron(0/2 * ? * MON-FRI *)

Page 29: Introduction to Serverless

service: text-analysis-via-sns-post-processing

frameworkVersion: ">=1.1.0 <2.0.0"

provider: name: aws runtime: nodejs4.3

functions:

analyzeNote: handler: analyzeNote.analyzeNote events: - sns: analyzeNote

Page 30: Introduction to Serverless

Services• Database

• FilesStorage

• Queues

• HTTP

• WebSockets

• IoT Management

Page 31: Introduction to Serverless
Page 32: Introduction to Serverless

Fin

Thanks for listening!

https://github.com/nikgrafhttps://twitter.com/nikgraf