$30 off During Our Annual Pro Sale. View Details »

Datascript: Serverless Architecture

Datascript: Serverless Architecture

Serverless architecture, FaaS status in December 2016.

Ladislav Prskavec

December 12, 2016
Tweet

More Decks by Ladislav Prskavec

Other Decks in Technology

Transcript

  1. Serverless
    Architecture
    Ladislav Prskavec
    Datascript, 13.12.2016 1

    View Slide

  2. Serverless is a hot topic in the software
    architecture world.
    — Mike Roberts
    Datascript, 13.12.2016 2

    View Slide

  3. Is Serverless
    buzzword?
    Datascript, 13.12.2016 3

    View Slide

  4. Backend as a Service
    and
    Function as a Service
    Datascript, 13.12.2016 4

    View Slide

  5. Backend as a Service (BaaS)
    » Firebase - DB + Auth
    » Hoodie - Offline first, PouchDB
    » Algolia - Search
    » Auth0 - SSO, Token Based Auth
    » Kinvey - Mobile Backend as Service
    » Syncano - Assemble your backend
    Datascript, 13.12.2016 5

    View Slide

  6. Function as a Service (FaaS)
    » Amazon Lambda & API Gateway (Nov'14)
    » IBM Bluemix Openwhisk (Feb'16)
    » Google Cloud Functions (Feb'16)
    » Azure Functions (Mar'16)
    » Webtask.io (Mar'15)
    Datascript, 13.12.2016 6

    View Slide

  7. Amazon Lambda
    Datascript, 13.12.2016 7

    View Slide

  8. Amazon Lambda - Inputs
    » Event Source
    » API Gateway
    » S3
    » Kinesis
    » DynamoDB
    » AWS Config
    » Amazon Cognito
    » AWS CloudFormation
    » ...
    Datascript, 13.12.2016 8

    View Slide

  9. Amazon Lambda - Processing
    » Compute Service
    » Languages (NodeJS 0.10 and 4.3, Java, Python, C#)
    » Security Model (IAM, VPC)
    » Cascading (AWS Step Functions)
    » Run code at any scale
    » Charged on execution scale
    Datascript, 13.12.2016 9

    View Slide

  10. Amazon Lambda - Outputs
    » Event
    » Storage
    » Messaging
    Datascript, 13.12.2016 10

    View Slide

  11. Cost effective
    Scenario - 16k req/day @ 200ms avg = 3200 s/day
    $2.97/day - 2 EC2 instances (upfront)
    $0.05/day - Lambda (1GB)
    Datascript, 13.12.2016 11

    View Slide

  12. AWS Serverless Application
    Model (AWS SAM)
    » https://github.com/awslabs/serverless-application-model
    » AWS SAM is a model used to define serverless applications on
    AWS.
    » Specification
    » AWS SAM is based on AWS CloudFormation.
    Datascript, 13.12.2016 12

    View Slide

  13. AWSTemplateFormatVersion: '2010-09-09'
    Transform: 'AWS::Serverless-2016-10-31'
    Resources:
    MyFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
    Handler: index.handler
    Runtime: nodejs4.3
    CodeUri: 's3://my-bucket/function.zip'
    Datascript, 13.12.2016 13

    View Slide

  14. Amazon States Language
    » Specification
    » Linter - https://github.com/awslabs/statelint
    Datascript, 13.12.2016 14

    View Slide

  15. {
    "Comment": "A Retry example of the Amazon States Language using an AWS Lambda Function",
    "StartAt": "HelloWorld",
    "States": {
    "HelloWorld": {
    "Type": "Task",
    "Resource": "arn:aws:lambda:us-east-1:123456789012:function:FailFunction",
    "Retry": [
    {
    "ErrorEquals": ["HandledError"],
    "IntervalSeconds": 1,
    "MaxAttempts": 2,
    "BackoffRate": 2.0
    },
    {
    "ErrorEquals": ["States.TaskFailed"],
    "IntervalSeconds": 30,
    "MaxAttempts": 2,
    "BackoffRate": 2.0
    },
    "ErrorEquals": ["States.ALL"],
    "IntervalSeconds": 5,
    "MaxAttempts": 5,
    "BackoffRate": 2.0
    }
    ],
    "End": true
    }
    }
    }
    Datascript, 13.12.2016 15

    View Slide

  16. Frameworks
    » Chalice
    » Apex
    » Serverless
    » Zappa
    » Sparta
    Datascript, 13.12.2016 16

    View Slide

  17. Chalice
    » Python
    » https://github.com/awslabs/chalice
    » microframework
    Datascript, 13.12.2016 17

    View Slide

  18. Apex - http://apex.run
    » in golang support nodejs, golang, python, java
    » optional terraform support
    » multiple deployment targets for different environments
    » idempotent deployments
    » author @tjholowaychuk
    Datascript, 13.12.2016 18

    View Slide

  19. Serverless - http://www.serverless.com
    » in NodeJS, actual version 1.3.0
    » support aws-nodejs, aws-python, aws-java-gradle, aws-java-
    maven, aws-scala-sbt, aws-csharp
    » config in serverless.yml
    » support env variables (support added into Lambda in
    November'16)
    » AWS CloudFormation
    Datascript, 13.12.2016 19

    View Slide

  20. Zappa - https://zappa.gun.io
    » in Python support Python
    » https://github.com/Miserlou/lambda-packages
    » https://github.com/Miserlou/django-zappa
    Datascript, 13.12.2016 20

    View Slide

  21. Sparta - http://gosparta.io
    » in Golang support Golang
    » CloudFormation
    Datascript, 13.12.2016 21

    View Slide

  22. Libraries and utils
    » claudiajs
    » aws-serverless-express
    Datascript, 13.12.2016 22

    View Slide

  23. ClaudiaJS
    » NodeJS
    » Claudia is not trying to change the way you structure or run
    projects.
    » Deployment utility
    » https://github.com/claudiajs/claudia
    Datascript, 13.12.2016 23

    View Slide

  24. AWS Serverless Express
    » extends ExpressJS
    » NodeJS 4.3 LTS
    » https://github.com/awslabs/aws-serverless-express
    » cannot use native packages
    » currently no support for binary data (AWS Gateway have
    support from Nov'16)
    Datascript, 13.12.2016 24

    View Slide

  25. Security
    » https://github.com/vandium-io/vandium-node
    » Powerful input validation, Forces values into correct types
    » JSON Web Token (JWT) verification and validation
    » Cross Site Request Forgery (XSRF) detection when using JWT
    » SQL Injection (SQLi) detection and protection
    » Environment variable mapping,
    » Free resources post handler execution
    » Handles uncaught exceptions
    » Promise support
    Datascript, 13.12.2016 25

    View Slide

  26. Testing
    » https://github.com/lambci/docker-lambda/
    » Docker images and test runners that replicate the live AWS
    Lambda environment
    » NodeJS 0.10/4.3
    » Python
    » Java8
    Datascript, 13.12.2016 26

    View Slide

  27. Architectures
    examples
    Datascript, 13.12.2016 27

    View Slide

  28. Datascript, 13.12.2016 28

    View Slide

  29. Datascript, 13.12.2016 29

    View Slide

  30. Datascript, 13.12.2016 30

    View Slide

  31. Datascript, 13.12.2016 31

    View Slide

  32. Datascript, 13.12.2016 32

    View Slide

  33. Datascript, 13.12.2016 33

    View Slide

  34. Datascript, 13.12.2016 34

    View Slide

  35. Datascript, 13.12.2016 35

    View Slide

  36. API Gateway & Lambda problems
    » limit 6MB on Lambda response
    » API Gateway don't support gzip
    » problems with with strange 500 errors without
    » not parsable error object from Lambda into API Gateway
    » API Gateway template system (based on Velocity templates)
    » problem with local testing API Gateway
    Datascript, 13.12.2016 36

    View Slide

  37. Q & A
    Datascript, 13.12.2016 37

    View Slide

  38. re:Invent 2016 sessions
    » Videos - https://gist.github.com/stevenringo/
    5f0f9cc7b329dbaa76f495a6af8241e9
    » Slides - http://www.slideshare.net/AmazonWebServices/
    tagged/reinvent2016
    Datascript, 13.12.2016 38

    View Slide

  39. Resources
    » https://aws.amazon.com/lambda/
    » https://github.com/anaibol/awesome-serverless
    » https://cloudcraft.co
    » https://github.com/lambci/docker-lambda/
    » http://www.allthingsdistributed.com/2016/05/aws-lambda-serverless-reference-
    architectures.html
    » https://www.thoughtworks.com/radar/techniques/serverless-architecture
    » https://serifandsemaphore.io/azure-cloud-functions-vs-aws-lambda-
    caf8a90605dd#.dbk2yntw1
    » https://github.com/donnemartin/awesome-aws
    Datascript, 13.12.2016 39

    View Slide