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

Serverless for (JavaScript) Developers

Serverless for (JavaScript) Developers

London JavaScript Community, February 7th, 2017

Serverless architectures simplify operations and maintenance of production applications, abstracting from the underlining infrastructure and OS. But what about development?

We are now two years in with tools such as AWS Lambda and what are the best practices to share from a development perspective?

In this session you will see some of the key points that can empower a JavaScript developer!

Danilo Poccia

February 07, 2017
Tweet

More Decks by Danilo Poccia

Other Decks in Programming

Transcript

  1. Serverless for
    (JavaScript)
    Developers
    Danilo Poccia
    @danilop danilop
    Technical Evangelist

    View Slide

  2. Danilo Poccia
    With AWS Lambda, you write your code and upload it to
    the AWS cloud. AWS Lambda responds to the events
    triggered by your application or your users, and auto-
    matically manages the underlying computer resources for you.
    Back-end tasks like analyzing a new document or processing
    requests from a mobile app are easy to implement. Your ap-
    plication is divided into small functions, leading naturally to a
    reactive architecture and the adoption of microservices.
    AWS Lambda in Action is an example-driven tutorial that
    teaches you how to build applications that use an event-driven
    approach on the back-end. Starting with an overview of AWS
    Lambda, the book moves on to show you common examples
    and patterns that you can use to call Lambda functions from
    a web page or a mobile app. The second part of the book puts
    these smaller examples together to build larger applications.
    By the end, you’ll be ready to create applications that take
    advantage of the high availability, security, performance, and
    scalability of AWS.
    What’s Inside

    Create a simple API

    Create an event-driven media sharing application

    Secure access to your application in the cloud

    Use functions from different clients like web pages
    or mobile apps

    Connect your application with external services
    Requires basic knowledge of JavaScript. Some examples are
    also provided in Python. No AWS experience is assumed.
    Danilo Poccia is a technical evangelist at Amazon Web Services
    and a frequent speaker at public events and workshops.
    To download their free eBook in PDF, ePub, and Kindle formats, owners
    of this book should visit www.manning.com/books/aws-lambda-in-action
    $49.99 / Can $57.99 [INCLUDING eBOOK]
    AWS Lambda IN ACTION
    SOFTWARE DEVELOPMENT/CLOUD
    Danilo
    Poccia
    M A N N I N G
    AWS Lambda IN ACTION
    MANNING
    “Clear and concise …
    the code samples are as well
    structured as the writing.”
    —From the Foreword by
    James Governor, RedMonk
    “A superb guide to an
    important aspect of AWS.”
    —Ben Leibert, VillageReach
    “Step-by-step examples
    and clear prose make this
    the go-to book for
    AWS Lambda!.”
    —Dan Kacenjar, Wolters Kluwer
    “Like Lambda itself, this
    book is easy to follow, concise,
    and very functional.”
    —Christopher Haupt, New Relic
    M A N N I N G
    SEE INSERT
    Danilo Poccia
    FOREWORD BY James Governor
    Event-driven serverless applications

    View Slide

  3. Function

    View Slide


  4. greetingsOnDemand

    View Slide

  5. Function

    View Slide

  6. Function

    View Slide

  7. Client Application
    Function
    invoke

    View Slide

  8. Client Application
    Function
    Database
    Files
    invoke
    read/write

    View Slide

  9. Client Application
    Function2
    Database
    Files
    Function1
    Function3
    invoke
    event trigger
    event trigger
    read/write

    View Slide

  10. Business Logic
    Client Application
    Function2
    Database
    Files
    Function1
    Function3
    invoke
    event trigger
    event trigger
    read/write

    View Slide

  11. Data Persistence
    Business Logic
    Client Application
    Function2
    Database
    Files
    Function1
    Function3
    invoke
    event trigger
    event trigger
    read/write

    View Slide

  12. Data Persistence
    Business Logic
    Client
    Application
    Functions
    Functions
    Functions Repositories
    Repositories
    Repositories
    API read/write
    event trigger

    View Slide

  13. Data Persistence
    Business Logic
    Client
    Application
    Functions
    Functions
    Functions Repositories
    Repositories
    Repositories
    API read/write
    event trigger
    read/write

    View Slide

  14. Data Persistence
    Business Logic
    Client
    Application
    Functions
    Functions
    Functions
    API
    Gateway
    Repositories
    Repositories
    Repositories
    API read/write
    event trigger
    read/write

    View Slide


  15. greetingsAPI

    View Slide

  16. How do I start?

    View Slide

  17. No Servers
    to Manage
    Continuous
    Scaling
    Subsecond
    Metering
    AWS Lambda

    View Slide

  18. 1 Million requests
    per month
    400,000 GB-seconds
    per month
    Free Tier
    AWS Lambda

    View Slide

  19. https://github.com/awslabs/aws-serverless-auth-reference-app
    Serverless reference app and backend API, showcasing authentication and
    authorization patterns using Amazon Cognito, Amazon API Gateway, AWS
    Lambda, and AWS IAM

    View Slide


  20. aws-serverless-auth-reference-app

    View Slide

  21. https://serverless.com

    View Slide

  22. Building An Infinitely Scalable Online Recording Campaign
    For David Guetta & UEFA

    View Slide

  23. Do I need to rebuild everything?

    View Slide

  24. https://github.com/awslabs/aws-serverless-express
    This library enables you to utilize AWS Lambda and Amazon API Gateway to
    respond to web and API requests using your existing Node.js application
    framework

    View Slide


  25. aws-serverless-express

    View Slide

  26. How to go beyond the timeout?

    View Slide

  27. function processList(itemList, context) {
    var item = itemList.shift();
    processItem(item, () => {
    if (itemList.length === 0) {
    console.log('Finished');
    } else if (context.getRemainingTimeInMillis() > TIME_THRESHOLD) {
    // Process remaning items
    processList(itemList, context);
    } else {
    console.log('Not finished');
    // Time is running out,
    // invoke self asynchrounously to process remaning items
    invokeSelf(itemList, context);
    }
    });
    }

    View Slide

  28. What about larger apps?

    View Slide

  29. https://github.com/awslabs/serverless-application-model

    View Slide

  30. >
    Serverless Continuous Integration and Deployment
    GitHub
    Amazon S3
    AWS CodeCommit
    AWS CodeBuild AWS CodeBuild
    third-party tools
    AWS CloudFormation
    Commit Build Test
    Deploy
    to Prod
    AWS CodePipeline + SAM

    View Slide


  31. serverless-application-model

    View Slide

  32. AWS Step Functions
    Sequential
    Steps
    Branching Steps
    (Choice of Path)
    Parallel
    Steps

    View Slide

  33. https://states-language.net/spec.html

    View Slide


  34. AWS Step Functions

    View Slide

  35. Event-Driven Architecture

    View Slide

  36. Name
    Email
    Create New User
    Submit
    Check the “Name” syntax is right
    (only letters and spaces)
    Check the “Email” syntax is right
    ([email protected])
    Create the new user using
    provided Name and Email
    User Interface Actions

    View Slide

  37. Name
    Email
    Create New User
    Submit
    Check the “Name” syntax is right
    (only letters and spaces)
    Check the “Email” syntax is right
    ([email protected])
    Create the new user using
    provided Name and Email
    User Interface Actions
    Observers
    Target Action

    View Slide

  38. Generate thumbnails
    Keep another database in sync
    Process streaming data
    Services Functions
    Platform
    Target Action
    Kinesis
    Stream
    DynamoDB
    Table
    S3
    Bucket

    View Slide

  39. area = length x width

    View Slide

  40. area = length x width
    Procedural Programming
    “This is a function!”

    View Slide

  41. area = length x width
    Procedural Programming
    “This is a function!”
    Reactive Programming
    “This is data binding!”

    View Slide

  42. A B
    Event-Driven Design
    For Services
    ”Service A triggers B"
    or better
    ”Service B is caused by A"

    View Slide

  43. A B
    C
    D
    E
    F
    ?
    ?
    What is causing
    services E and F?

    View Slide

  44. A B
    C
    D
    E
    F
    New services (E, F)
    are triggered caused by C

    View Slide

  45. A B
    C
    D
    E
    F
    It can be cyclic
    Think of
    acknowledgements

    View Slide

  46. Each service
    has local visibility
    A B
    C
    D
    E
    F

    View Slide

  47. What I need to know
    (input events)
    1
    A B
    C
    D
    E
    F

    View Slide

  48. What I need to do
    (internal logic)
    2
    A B
    C
    D
    E
    F

    View Slide

  49. Who I need to notify
    (output events)
    3
    A B
    C
    D
    E
    F

    View Slide

  50. Who I need to notify
    (output events)
    What I need to know
    (input events)
    What I need to do
    (internal logic)
    1
    2
    3
    B

    View Slide

  51. Distributed Data Flow
    Vs
    Centralised Workflow

    View Slide

  52. Choreography
    Vs
    Orchestration

    View Slide

  53. Microservices
    Distributed Systems

    View Slide

  54. Monolith
    Service
    Service
    μ
    μ
    μ
    space (distribution, mobility)
    time (concurrency, latency)
    μ
    μ
    μ
    μ
    “Distributed
    in Time and Space”
    [Jonas Bonér]

    View Slide

  55. “…a diagram of
    two microservices
    and their shared database”
    Data should drive
    the boundaries

    View Slide

  56. A
    C
    I
    D
    tomic
    onsistent
    solated
    urable

    View Slide

  57. A
    C
    I
    D
    tomic
    onsistent
    solated
    urable
    A
    C
    I
    D
    ssociative
    ommutative
    dempotent
    istributed
    ACID 2.0

    View Slide

  58. Scale
    from Prototype to Production

    View Slide

  59. Responsive
    Resilient
    Elastic
    Message Driven
    The Reactive Manifesto

    View Slide

  60. Asynchronous
    communication
    is not enforced
    by serverless architectures
    Responsive
    Resilient
    Elastic
    Message Driven
    The Reactive Manifesto

    View Slide

  61. Lambda Everywhere

    View Slide

  62. AWS Greengrass

    View Slide

  63. AWS Snowball Edge

    View Slide

  64. AWS Snowball Edge

    View Slide

  65. AWS Snowmobile

    View Slide

  66. Lambda@Edge

    View Slide

  67. Build Apps With Services,
    Not Servers

    View Slide

  68. https://aws.amazon.com/lambda
    https://github.com/awslabs/aws-serverless-auth-reference-app
    https://github.com/awslabs/aws-serverless-express
    https://serverless.com
    https://github.com/awslabs/serverless-application-model
    https://states-language.net/spec.html
    https://github.com/danilop/AWS_Lambda_in_Action
    For Your Reference

    View Slide

  69. Thank You!
    Danilo Poccia
    @danilop danilop
    Technical Evangelist

    View Slide