Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Life Without Servers. Yes We Can!

Life Without Servers. Yes We Can!

How to take advantage of the AWS platform to create an efficient, scalable and "economically" sustainable software ecosystem. All this without OS to install or "patch" and especially without servers to maintain.

Luca Milan

March 15, 2017
Tweet

More Decks by Luca Milan

Other Decks in Programming

Transcript

  1. Agenda ◉ Intro & background ◉ Serverless Paradigm (Background, State)

    ◉ Deep Dive on AWS Lambda ◉ Serverless Application Framework ◉ Demo, demo, demo :) ◉ Q&A
  2. Instant deployment Predictable performances Low latencies Fine Grain Services Decoupling

    “as usual” Continuous Development Deployment Monitoring
  3. 2017 A long time ago monolith micro-services functions Business Logic

    Shift containers virtualisation physical Cloud Evolution sysadmin dev-ops IT Culture months seconds Deploy Time days hours no-ops
  4. Evolution CPU utilization in data centers (big public clouds) max

    min bare metal server virtualization containers serverless > 30% 5% 10-15% 20-25% The lower the utilization, the less value you’re getting for your money
  5. Transactions Service Oriented Architecture Distributed Data / Services (ACID, 2PC,

    RPC) (past - then) exactly once delivery at least once delivery A long time ago 2017 Changes requires a massive shift in the way IT operates Message-Passing Shared-Nothing
  6. Business Operations and Cloud Resources are deeply linked Monolith Micro-Services

    Functions Domain Driven Design Lean Agile Containers are the enablers for FaaS DevOps S.O.L.I.D.
  7. doesn’t mean servers are no longer involved… It simply means

    that developers no longer have to think "that much" about them. “Why The Future Of Software And Apps Is Serverless”, Ken Fromm
  8. “ Serverless computing is a major disruption from the mainstream,

    responding to requests for computation and processing data based on events and ensuring application code loads, executes, and runs with sufficient resources.
  9. “ There’s a lot of similarity between a serverless approach

    and the philosophies of functional programming. Breaking down your application logic into small, discrete parts (or, pure functions) you can explicitly declare, test and control application logic in a demonstrable and repeatable way.
  10. “ Moving away from servers and infrastructure concerns, as well

    as allowing the developer to primarily focus on code, is the ultimate goal behind serverless.
  11. “ Serverless computing, generates cost efficiency by eliminating the need

    to scale up an entire application; instead, it distributes and scales only specific functions. The user pays only for the time function in serving the requests.
  12. PaaS vs FaaS The big difference from PaaS and FaaS

    is the capacity of “scaling transparently”.
  13. Specifications 1. It’s the next PaaS, where devs just write

    the business logic 2. Discrete services that react to events or requests 3. Scaled, fault tolerant and secure by provider 4. Significantly depend on third-party services 5. Cost-efficient: you will never pay for idle servers and you are charged by individual invocations
  14. Pros No Provisioning & Zero Admin Full Managed Solid Security

    Model (by IAM) Simple Development & Deployment (a zip file) Reduced TTM & Developer Focused Pay Per Execution & Run when I need it Continuous Scaling & Fault Tolerance
  15. Cons Less vendor control You can no longer store application

    & state data in local server memory There’s no dedicated hardware option with serverless Testing is more complicated We have some Lambda limits Vendor Lock-In
  16. Simple Storage Service ◉ Provide objects to S3 ◉ We

    don’t know how or where objects are stored ◉ S3 stores those objects transparently ◉ We don't have space or disks to manage ◉ We are charged only by amount stored
  17. Lambda Computation Service ◉ Provide code to Lambda engine ◉

    Lambda executes code on demand ◉ We don’t know how or where code are executed ◉ We don't have VM’s or containers to manage ◉ We are charged only by invocations / execution time
  18. Event Driven model ◉ Code execution ◦ Execution when triggered

    by an event ◦ Fully automated (resources allocation) ◉ Require ◦ An event source (where the event happens) ◦ A function to execute (a zip package) ◦ An event source mapping (metadata) ◦ Right permissions (role & policies)
  19. Event Sources ◉ What ? ◦ Event sources sending events

    to lambda processing ◦ Lambda then executes code by passing the event payload to the function handler ◉ Who ? ◦ Api calls made by AWS SDK ◦ Manual user invocation via the Web Console ◦ HTTP requests through the Api Gateway ◦ Scheduled (Cron/Jobs) ◦ Events raised in AWS (S3, Kinesis, DynamoDb, etc..)
  20. Event Sources List ◉ Supported AWS Event Sources ◦ Amazon

    CloudWatch ◦ Cognito ◦ Api Gateway ◦ Kinesis & DynamoDB ◦ Simple Storage Service ◦ Simple Notification Service ◦ Simple Email Service ◦ etc... ◉ Other AWS Services ◦ Custom application ◦ Services that publish event to above event sources
  21. Lambda invocation ways ◉ Event (async) ◦ Lambda function doesn’t

    send a response back to the event source. ◦ Events are queued before being used to invoke the Lambda function (retry policies) ◦ Used by S3, SNS ◉ Request-Response (sync) ◦ Forces Lambda to execute the function synchronously and return the response to the caller. ◦ Used by API Gateway, AWS Console, AWS SDK, etc.
  22. Event models: Push vs Pull ◉ Push (non-stream based) ◦

    A service (like S3 o API Gateway) publishes an event to Lambda and directly invokes the function ◦ Event source mapping reside in the service (S3) ◉ Pull (stream based) ◦ Lambda runtime polls streaming event source (Kinesis or DynamoDB) and invokes the function when new data arrives. ◦ Event source mapping reside in Lambda
  23. EVENT SOURCES S3, SNS, API-G etc. ESM - PULL ESM

    - PUSH Async invoke Sync invoke Kinesis Streams and DynamoDB Streams Events are queued, support retries on errors and DLQ Event Source is responsible for retries
  24. Pillars 1. Function Handler 2. Context Object 3. Logging 4.

    Errors * all samples are for NodeJS runtime
  25. Event: contains the input data (come from event source) Context:

    contains metadata about current execution Callback: returns errors or success message to the caller File JS: handler.js + Exports: hello = handler.hello
  26. All logs are stored in Cloud Watch Lambda logs can

    be bound to an Elastic Search cluster
  27. $0.00001667 for every GB-second Duration of execution (GB-s) rounded up

    to nearest 100ms First 400000 GB-s per month are free
  28. Key Features • Application LifeCycle Management • Manages Code &

    Infrastructure • Scaffolding & Automation • Multi-Runtimes (NodeJs, Java, Pyton, etc...) • Permission Management (full IAM) • Multi-Providers (less vendor lock-in) • Local Development • Extensibility in mind (plug-ins model) • Open source • Community Support • and much more...
  29. #Sign Up for Amazon Web Services https:/ /aws.amazon.com #Install AWS

    CLI https:/ /github.com/aws/aws-cli/releases Install serverless globally via npm npm install serverless -g Create an AWS Lambda project in Node.js serverless create --template aws-nodejs Install SLS framework
  30. #serverless.yml service: intro provider: name: aws runtime: nodejs6.10 stage: dev

    region: eu-west-1 functions: hello: description: "Hello WebDev lambda!" handler: handler.hello Serveless YML “A Service is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use”
  31. Live Coding A sample to see Serverless Framework in action

    ➔ step by step: ➔ create an Hello World API ➔ deploy the API to un AWS environment ➔ invoke the API endpoint to see it working ➔ add a function and new endpoint to the API ➔ deploy the updated API ➔ invoke the new endpoint
  32. Demos An array of samples ➔ 01 - Intro ➔

    02 - events ➔ 03 - rest api recipes ➔ 04 - graphql api ➔ 05 - graphql api offline ➔ 06 - dynamodb stream ➔ 07 - step functions
  33. Questions ? You can find us at • [email protected]

    https://github.com/lucamilan Thanks!