Slide 1

Slide 1 text

Fun With Serverless JavaScript Lorna Mitchell, IBM

Slide 2

Slide 2 text

The Serverless Revolution The big secret is: there ARE servers! It's not actually NoOps, just awesome container-based ops done by someone else :) @lornajane

Slide 3

Slide 3 text

The Serverless Revolution Faas: Functions As A Service You focus only on: • the inputs • the outputs • the logic in between Charges are usually per GB/sec @lornajane

Slide 4

Slide 4 text

When To Go Serverless • For occasional server needs (contact form on static site) • For very variable traffic levels (millions of IoT sensors) • To provide extra compute resource without extending existing platform (classic example: PDF generation) @lornajane

Slide 5

Slide 5 text

Serverless Providers • Amazon have AWS Lambda • OpenWhisk is open source, also available on Bluemix • Google have Google Cloud Functions • Iron.io have a good functions offering • Microsoft have Azure Functions @lornajane

Slide 6

Slide 6 text

Why JavaScript? It's an awesome language! @lornajane

Slide 7

Slide 7 text

Why JavaScript? It's an awesome language! (it's also well-supported on all these platforms) @lornajane

Slide 8

Slide 8 text

Let The Fun Begin @lornajane

Slide 9

Slide 9 text

Amazon Lambda • Install awscli command line tool (there is also a web interface) • Set up permissions via IAM and then use aws configure to get that set up • Write some JS, and zip it (for me: index.js -> hello.zip) @lornajane

Slide 10

Slide 10 text

Amazon Lambda Create your lambda function by supplying the zip file and some options: aws lambda create-function \ --function-name hello1 \ --runtime nodejs6.10 \ --role "arn:aws:iam::283476131276:role/service-role/Alexa" --description "A demo first Lambda function" \ --handler index.handler \ --zip-file fileb://hello.zip @lornajane

Slide 11

Slide 11 text

Amazon Lambda (if you want to edit your code and redeploy it) aws lambda update-function-code \ --function-name hello1 \ --zip-file fileb://hello.zip Run your lambda function: aws lambda invoke --function-name hello1 output.txt @lornajane

Slide 12

Slide 12 text

Hello World Lambda exports.handler = function(event, context) { context.succeed("Hello, World!"); }; @lornajane

Slide 13

Slide 13 text

Hello World OpenWhisk exports.main = function(args) { return({"message": "Hello, World!"}); }; @lornajane

Slide 14

Slide 14 text

Bluemix OpenWhisk Get the wsk CLI tool, and log it in using copied command from web interface Zip and deploy/update your code zip hello.zip index.js wsk action update --kind nodejs:6 \ demo/hello1 hello.zip @lornajane

Slide 15

Slide 15 text

Bluemix OpenWhisk Run your action from the CLI: wsk action invoke --blocking demo/hello1 Enable web access, and web request your action: wsk action update demo/hello1 --web true curl https://openwhisk.ng.bluemix.net/api/v1/web/ \ Lorna.Mitchell_Working/demo/hello1.json @lornajane

Slide 16

Slide 16 text

Serverless + HTTP FaaS + HTTP = Microservices! @lornajane

Slide 17

Slide 17 text

Microservices @lornajane

Slide 18

Slide 18 text

More Fun and More JavaScript @lornajane

Slide 19

Slide 19 text

Alexa: Amazon Echo You speak, the device sends the sound to the cloud and speaks back the response it gets. @lornajane

Slide 20

Slide 20 text

Example: Project Codename Based on: https://www.npmjs.com/package/project-name-generator "Alexa, ask Project Codename for a new project name" https://github.com/lornajane/alexa-project-codename @lornajane

Slide 21

Slide 21 text

Project Codename: the Code function main(args) { var generate = require('project-name-generator'); var random = generate().spaced; var response = { "version": "1.0", "response" :{ "shouldEndSession": true, "outputSpeech": { "type": "PlainText", "text": "project codename. " + random } } } return(response); } exports.main = main; @lornajane

Slide 22

Slide 22 text

Project Codename: invoke wsk action invoke --blocking alexa/project-codename ... random 2-word responses appear. @lornajane

Slide 23

Slide 23 text

Project Codename: voice Let's ask Alexa! @lornajane

Slide 24

Slide 24 text

The Serverless Revolution @lornajane

Slide 25

Slide 25 text

Resources • Blog post: http://lrnja.net/2l9t1bX • Serverless framework: https://github.com/serverless/serverless • OpenWhisk on Bluemix: https://www.ibm.com/cloud-computing/bluemix/openwhisk • Serverless Architecture article: https://martinfowler.com/articles/serverless.html @lornajane