Going Serverless

Introduction to Azure Functions and Amazon Lambda

Guido García · @palmerabollo · 2016

baremetal

virtual machines

containers

serverless

reactive code

run code in response to events

benefit #1
it can be "cheaper"

no idle infrastructure

benefit #2

"no ops"

"can't someone else do it?"

– Homer Simpson 

benefit #3

"good dev practices"

single responsibility

software that fits in your head

Alternatives

Amazon Lambda

Azure Functions (preview)

Google Cloud Functions (alpha)

IBM OpenWhisk

Hook.io

Iron.io

...
github.com/anaibol/awesome-serverless

Example. Azure Function

module.exports = (context, req) => {
    context.done(null, "Hello World");
};

grouped in app

console

Example. AWS Lambda

def lambda_handler(event, context):
    return "Hello World"
    # raise Exception('Something went wrong')
exports.handler = (event, context, callback) => {
    callback(null, 'Hello World');
    // callback(new Error('Something went wrong'));
};

python

nodejs

webapp: static + dynamic

object storage processing

(transcoding, ocr, image processing...)
aka storlets

Languages

  • Amazon Lambda
    • Node.js (4.3), C#, Python, Java
  • Azure Functions
    • Node.js (5.9), C#, F#, Python, PHP, PowerShell, etc
  • Google Cloud Functions
    • Node.js

Pricing

  • Amazon Lambda
    • 1M req/month for free
    • then $0.20/1M req + $0.06 per GB-h
  • Azure Functions
    • 1M req/month for free
    • then $0.20/1M req + $0.06 per GB-h
  • Google Cloud Functions
    • unknown yet

drawback #1

management is hard

use a management tool (DDIY)

  • serverless.com (js, python, c#) · AWS+
  • apex.run · AWS
  • zappa.io (python) · AWS
  • ...

drawback #2

cold start

heartbeat = keep it warm
more memory = increase CPU allocation

drawback #3

lock in

  • Amazon Lambda
    • Closed
    • re:Invent 2016 AWS SAM – Serverless App Model
  • Azure Functions
    • The runtime used by Azure Functions is open
    • https://github.com/azure/azure-webjobs-sdk-script
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  MySimpleFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs4.3
      CodeUri: s3://<bucket>/MyCode.zip
      MemorySize: 1024
      Timeout: 15
      Events:
        MyUploadEvent:
          Type: S3
          Properties:
            Id: !Ref Bucket
            Events: Create
  Bucket:
    Type: AWS::S3::Bucket

AWS SAM Example

AWS re:Invent 2016

  • Step Functions · https://aws.amazon.com/step-functions
    • Build workflows of Lambda functions
  • Amazon Lex · https://aws.amazon.com/lex/
    • Build chatbots integrated with Lambda functions
  • Lambda@Edge
    • Run Lambda functions at the AWS Edge locations in response to CloudFront (CDN) events
  • Greengrass · https://aws.amazon.com/greengrass
    • IoT, run lambda functions on devices

end

Made with Slides.com