Introduction to Serverless Computing

Colin J. Ihrig / @cjihrig

Serverless Computing Model

  • There are still servers!
  • Servers are hidden from developers
  • Infrastructure provider manages servers and scaling
  • Functions are the unit of deployment (FaaS)
  • Only billed when your code runs

Burdens Shifted to Providers

  • Server provisioning
  • Availability and uptime
  • Scaling in response to traffic
  • Server software updates
  • Security

Serverless Offerings


AWS Lambda

Auth0 Webtasks

IBM OpenWhisk

Google Cloud Functions

Examining Lambda

Pricing

  • Charged for requests and execution time (GB-sec)
  • 1M free requests per month
  • $0.20 per additional 1M requests
  • Execution time billed in 100ms increments
  • Memory utilization impacts GB-sec
  • 400,000 free GB-sec in free tier

Use Cases

Example Architecture


Image taken from blog.cloudthat.com

Lambda and Containers

  • Cold starts load code into a new container
  • Cold start penalty can be avoided by container reuse
  • Container is destroyed after inactive period
  • Container reuse is not guaranteed
  • More containers created in response to load

Writing Lambda Functions

'use strict'; // Initialization code function handler(event, context, callback) { // Handler code callback(null, { msg: 'Hello World!' }); } module.exports.handler = handler;
  • event is used to pass data to Lambda
  • context contains Lambda runtime information
  • callback is a Node-style, error first callback function

Deployment Packages

  • .zip file containing all code and dependencies
  • Package can contain executables as well
    • process.env.PATH += `:${process.env.LAMBDA_TASK_ROOT}`;
  • Upload using Amazon's web UI, CLI, or aws-sdk
  • Or via third party modules (lambundaler, serverless)

Invoking Lambda Functions

  • Must be invoked by something
    • Testing with Lambda directly
    • HTTP request with API Gateway
    • In response to AWS events
    • Scheduled event
    • AWS CLI
    • Arbitrary application code!
  • Supported in hapi via hapi-gateway

The Serverless Framework

  • Automates many Lambda and API Gateway tasks
  • Currently only Lambda, but other providers coming
  • Very (large) configuration file centric

Additional Resources

The End

Questions?