Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Serverless IoT with AWS
Lambda
Walkthrough, Enterprise
Implications
Bob Balaban
SGAArchitect
Serverless-Boston Meet-up Nov...
Agenda
• “Serverless” Use Case: IoT
• Demo overview
• Click a button, get an email
• Step by Step
• Config
• Test
• Code
•...
IoT: Internet of Things
• Many (103? 106? 109?) devices sending data to a collection point for
(real time?) analysis and r...
Microservices + Serverless
• The right service
• For the right price
• In the right location
• At the right time
• On dema...
Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
Demo: Click a button, get an email
Setup and Coding
• Configure the button
• Unit Test
• Write the code
• Unit Test
• End-to-end Test
Serverless-Boston Meet-...
Configure the Button - 1
• Go to AWS IoT console
• Create a “thing” (these are region-specific!!)
• Create x509 certificat...
Configure the Button - 2
• Certificate -> Attach Policy
• Certificate -> Attach Thing
• Find “Custom IoT Endpoint”
• (e.g....
Configure the Button - 3
• Test your connectivity
• IoT console, “MQTT Client” tab
• Generate client ID, Connect
• Subscri...
Write the Lambda Code - 1
• AWS tutorial:
http://docs.aws.amazon.com/iot/latest/developerguide/iot-button-
lambda.html
• G...
Write the Lambda Code - 2
• Go to “Configure Function”, review the code in the editor
• Replace hardcoded email string
• F...
Test it!
• Click the button
• Blinking white light
• Steady green
• Email should arrive within a few seconds
• Go to Cloud...
Enhance it!
• Hardcoded email address is not really practical
• Create DynamDb table that maps button ID to an email addr
...
Enterprise Perspectives
• Config needs way more automation
• Try doing 1000 buttons…
• Then try managing 1000 lambda funct...
Other Options for Invoking Functions (Lambda
Events)
• AWS Services – Publishes events which invoke Lambda
• S3 – Asynchro...
Serverless Challenges
LessOps requires new ways of thinking about deployment, testing, etc.
Serverless billing can be ch...
Thank you!
Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
Q & A
Upcoming SlideShare
Loading in …5
×

Serverless IoT with AWS Lambda

215 views

Published on

Serverless IoT with AWS Lambda - Walkthru, Enterprise Implications

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Serverless IoT with AWS Lambda

  1. 1. Serverless IoT with AWS Lambda Walkthrough, Enterprise Implications Bob Balaban SGAArchitect Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  2. 2. Agenda • “Serverless” Use Case: IoT • Demo overview • Click a button, get an email • Step by Step • Config • Test • Code • Test again • Enterprise perspectives • Q&A Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  3. 3. IoT: Internet of Things • Many (103? 106? 109?) devices sending data to a collection point for (real time?) analysis and reporting • Many issues at scale! • Software (architecture and implementation) • Hardware (security, deployment, maintenance…) • AWS Lambda is an interesting approach • Fits with microservices architectures • Small, stateless (usually) chunks of bizlogic • Potential for significant cost savings (you don’t pay for idle time) • Azure Functions, Google Cloud Functions, IBM OpenWhisk… Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  4. 4. Microservices + Serverless • The right service • For the right price • In the right location • At the right time • On demand! Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  5. 5. Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc. Demo: Click a button, get an email
  6. 6. Setup and Coding • Configure the button • Unit Test • Write the code • Unit Test • End-to-end Test Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  7. 7. Configure the Button - 1 • Go to AWS IoT console • Create a “thing” (these are region-specific!!) • Create x509 certificate for the button, activate • Download cert and private key files • Create an IoT Policy to authorize the button to access services Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Publish", "Resource": "*" } ]}
  8. 8. Configure the Button - 2 • Certificate -> Attach Policy • Certificate -> Attach Thing • Find “Custom IoT Endpoint” • (e.g. <account#>.iot.us-west-2.amazonaws.com) • Program the button: • Hold down button until blue light flashes (sets up wi-fi hotspot • Connect laptop wi-fi to hotspot (pw is last 8 digits of button serial number) • Browse to http://192.168.0.1/index.html • Enter wi-fi connection info (SSID, pw if needed) • Upload certificate, private key, add in custom endpoint… Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  9. 9. Configure the Button - 3 • Test your connectivity • IoT console, “MQTT Client” tab • Generate client ID, Connect • Subscribe to topic “iotbutton/+” (or instead of +, specific button serial number) • Click the button! Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  10. 10. Write the Lambda Code - 1 • AWS tutorial: http://docs.aws.amazon.com/iot/latest/developerguide/iot-button- lambda.html • Go to AWS Lambda Console • “Create a Lambda Function” • Select “iot-button-email” blueprint, select runtime (node.js-4.3) • On “Configure Triggers” page, select “IoT Button”, enter serial number Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  11. 11. Write the Lambda Code - 2 • Go to “Configure Function”, review the code in the editor • Replace hardcoded email string • For authorization: “Create role from template” • Give it a name • Select template “AWS IoT Button permissions” • Allows function code to access outside services (especially SNS) • Click “Create” • Add trigger: AWS IoT -> IoTButton, enter serial number • Unit Test: • Click “Test”, you should get an email • Actions -> Configure Test event”, set it up to send the right data Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  12. 12. Test it! • Click the button • Blinking white light • Steady green • Email should arrive within a few seconds • Go to CloudWatch • Logs • Click on button log stream • Review log events, see billing info on log “REPORT” • Look at metrics (not especially interesting for small numbers of events) Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  13. 13. Enhance it! • Hardcoded email address is not really practical • Create DynamDb table that maps button ID to an email addr • Re-factor event handler to look up email dynamically • Node.js async “callback” pattern • Create another table to record hits • Modify Lambda role permissions, add “Microservice permissions” • Add some extra logging • Test it! Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  14. 14. Enterprise Perspectives • Config needs way more automation • Try doing 1000 buttons… • Then try managing 1000 lambda functions… • Pre manufacture hardware with required files? How to keep it secure… • Policies/permissions (button, lambda) • “Printf” style debugging is SO 1970s • Need local framework(s) to debug code for real • You want to know how much it’s going to cost to run your system BEFORE you go to production • http://serverlesscalc.com/# • APM tools? • Idle-time behavior, you pay for spin-up time Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  15. 15. Other Options for Invoking Functions (Lambda Events) • AWS Services – Publishes events which invoke Lambda • S3 – Asynchronous invocation by S3 • DynamoDB / Kinesis Streams – Lambda polls the stream(s) and invokes synchronously • Cognito – Invokes synchronously • HTTPS – Custom REST API and endpoint using API Gateway • Custom Apps – Client/mobile/web app publish events via SDKs • Scheduled Events – Schedule events via AWS Lambda Console • Hours, Days, Weeks, cron expression Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  16. 16. Serverless Challenges LessOps requires new ways of thinking about deployment, testing, etc. Serverless billing can be challenging and not always cheaper than IaaS. Invoking functions requires the cloud vendors to launch containers (startup considerations). New development skills required including cloud knowledge Small stateless functions require new coding patterns Stateful coding requires even more skill Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc.
  17. 17. Thank you! Serverless-Boston Meet-up Nov. 2, 2016, ©SGA, Inc. Q & A

×