Share
Embed
Fun with Serverless Apps
Presentation at JeffConf in London, with Alexa-related demos
Lorna Mitchell
July 07, 2017
Transcript
34 slides
-
The Serverless Revolution Faas: Functions As A Service You focus
only on: • the inputs • the outputs • the logic in between Charges are usually per GBsec @lornajane -
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 -
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 -
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 -
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 -
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 demo is the package name @lornajane -
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 -
Alexa: Amazon Echo You speak, the device sends the sound
to the cloud and speaks back the response it gets. @lornajane -
Example: Project Codename https://www.npmjs.com/package/project-name-generator "Alexa, ask Project Codename for a
new project name" @lornajane -
Example: Project Codename https://www.npmjs.com/package/project-name-generator "Alexa, ask Project Codename for a
new project name" @lornajane -
Example: Project Codename https://www.npmjs.com/package/project-name-generator "Alexa, ask Project Codename for a
new project name" @lornajane -
Example: Project Codename https://www.npmjs.com/package/project-name-generator "Alexa, ask Project Codename for a
new project name" @lornajane -
Project Codename: the Setup Use the Alexa dashboard to create
your "skill" • Skill name: appears in the dashboard • Language: Your skill must be enabled for your region • Endpoint: a Lambda ARN or an HTTP endpoint @lornajane -
Project Codename: the Setup Utterances - what the user can
say to get this to work Format: [intent] [words the user can say] NewCodename for a new name NewCodename for a new project name NewCodename for a new project codename RecentCodenames about recent codenames RecentCodenames to say that again RecentCodenames to repeat codenames There is also an Interaction Builder @lornajane -
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 -
Project Codename: invoke wsk action invoke --blocking alexa/project-codename ... random
2-word responses appear. @lornajane -
Quiz: the Setup This skill asks the user a simple
maths question • Intent: Quiz • Slots: Number (there are predefined data types) The "dialog" feature helps to prompt the user for input There is a "session" to store data between requests @lornajane -
Quiz: the Conversation Human Alexa, ask Lorna for a quiz
Alexa Ready? What is three plus five? Human Eight! Alexa Well done! Eight is correct. OR Human Fourty-two! Alexa You said fourty-two, but the correct answer is eight. @lornajane -
Quiz: Step by Step Human Alexa, ask Lorna for a
quiz { "version":"1.0", "session":{ "new":true }, "request":{ "type":"IntentRequest", "intent":{"name":"Quiz", "confirmationStatus":"NONE", "slots":{ "Number":{ "name":"Number", "confirmationStatus":"NONE" } } }, "dialogState":"STARTED" } } @lornajane -
Quiz: Step by Step Alexa Ready? What is three plus
five? { "outputSpeech":{ "type":"PlainText", "text":"Ready? What is 3 plus 5?" }, "directives":[ { "type":"Dialog.ElicitSlot", "slotToElicit":"Number" } ], "shouldEndSession":"false" } @lornajane -
Quiz: Step by Step Human Eight! { "version": "1.0", "session":
{ "new": false }, "request": { "type": "IntentRequest", "intent": { "name": "Quiz", "confirmationStatus": "NONE", "slots": { "Number": { "name": "Number", "value": "8", "confirmationStatu } }, "dialogState": "IN_PROGRESS" } } @lornajane -
Quiz: Step by Step Alexa Well done! Eight is correct.
{ "outputSpeech":{ "type":"PlainText", "text":"Well done! 8 is correct" }, "shouldEndSession":"true" } @lornajane -
Resources • Project codename skill: https://github.com/lornajane/alexa-project-codename • Serverless framework: https://github.com/serverless/serverless
• OpenWhisk on Bluemix: https://www.ibm.com/cloud-computing/bluemix/openwhisk • My blog: https://lornajane.net @lornajane