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

Serverless for Developers

Serverless for Developers

Cloud Conf, Turin, March 16th, 2017

Tips for Your Next App.

Danilo Poccia

March 16, 2017
Tweet

More Decks by Danilo Poccia

Other Decks in Programming

Transcript

  1. Serverless for Developers Tips for Your Next App Danilo Poccia

    @danilop danilop AWS Technical Evangelist
  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
  3. Business Logic Client Application Function2 Database Files This image cannot

    currently be displayed. Function1 Function3 invoke event trigger event trigger read/write
  4. Data Persistence Business Logic Client Application Function2 Database Files Function1

    Function3 invoke event trigger event trigger read/write
  5. Data Persistence Business Logic Client Application Functions Functions Functions Repositories

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

    Gateway Repositories Repositories Repositories API read/write event trigger read/write
  7. Request – Input Format { "resource": "Resource path", "path": "Path

    parameter", "httpMethod": "Incoming request's method name", "headers": { Incoming request headers }, "queryStringParameters": { Query string parameters }, "pathParameters": { Path parameters }, "stageVariables": { Applicable stage variables }, "requestContext": { Request context, including authorizer-returned key-value pairs }, "body": "A JSON string of the request payload", "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode" } Response – Output Format { "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... }, "body": "...” } Lambda Function Amazon API Gateway
  8. No Servers to Manage Continuous Scaling Subsecond Metering AWS Lambda

    1 Million requests per month 400,000 GB-seconds per month Free Tier
  9. https://github.com/awslabs/chalice $ pip install chalice $ chalice new-project helloworld &&

    cd helloworld $ cat app.py from chalice import Chalice app = Chalice(app_name="helloworld") @app.route("/") def index(): return {"hello": "world"} $ chalice deploy ... Your application is available at: https://endpoint/dev $ curl https://endpoint/dev {"hello": "world"}
  10. 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
  11. 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
  12. 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); } }); } For example…
  13. </> 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
  14. 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
  15. 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
  16. Generate thumbnails Keep another database in sync Process streaming data

    Services Functions Platform Target Action Kinesis Stream DynamoDB Table S3 Bucket
  17. area = length x width Procedural Programming “This is a

    function!” Reactive Programming “This is data binding!”
  18. A B Event-Driven Design For Services ”Service A triggers B"

    or better ”Service B is caused by A"
  19. A B C D E F ? ? What is

    causing services E and F?
  20. A B C D E F New services (E, F)

    are triggered caused by C
  21. A B C D E F It can be cyclic

    Think of acknowledgements
  22. 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
  23. Serverless for Developers Tips for Your Next App Danilo Poccia

    @danilop danilop AWS Technical Evangelist