introduction to serverless
Post on 08-Feb-2017
364 Views
Preview:
TRANSCRIPT
Introduction to Serverless
What is Serverless?• Serverless Book
• Serverless Conference
• Serverless Framework
• Serverless Inc.
• Serverless Architectures
• Serverless Application Model
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
Function as a unit of application logic
How does it work?
• New instances based on invocation demand
• Events trigger a function
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
Isn’t that limiting?
Yes! 🙃
Benefits
• 📈 Auto scaling
• 💵 Pay per execution
• 🎪 Event Driven
• 🗝 Security
Common Use Cases
• 🕸 Web Applications
• 📱 Mobile & IoT Backends
• 💹 Data Processing
• 🤖 Chatbots
Providers• AWS Lambda
• Google Cloud Functions
• Microsoft Functions
• IBM Openwhisk
• Auth0 Webtasks
• IronIO IronFunctions
• many more …
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
Challenges• Monitoring
• Cold starts
• Development flow
• Application architecture
• Service Discovery
• Service Communication
Deployment Options
• User Interface
• API calls (Serverless Framework v0, Claudia, Zappa, Apex)
• CloudFormation (Serverless Framework v1, SAM)
Deploy via the UI
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);});
Deploy via CloudFormation
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
// 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);};
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 *)
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
Services• Database
• FilesStorage
• Queues
• HTTP
• WebSockets
• IoT Management
Fin
Thanks for listening!
https://github.com/nikgrafhttps://twitter.com/nikgraf
top related