Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to AWS Lambda and Serverless Applications

272 views

Published on

In this session we’ll take a high-level overview of AWS Lambda, a serverless compute platform that has changed the way that developers around the world build applications. We’ll explore how Lambda works under the hood, the capabilities it has, and how it is used. By the end of this talk you’ll know how to create Lambda based applications and deploy and manage them easily.

Speaker: Chris Munns - Principal Developer Advocate, AWS Serverless Applications, AWS

  • Be the first to comment

Introduction to AWS Lambda and Serverless Applications

  1. 1. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Pop-up Loft Introduction to AWS Lambda and Serverless Applications Chris Munns Principal Developer Advocate AWS Serverless
  2. 2. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved About me: Chris Munns - munns@amazon.com, @chrismunns – Principal Developer Advocate - Serverless – New Yorker – Previously: • AWS Business Development Manager – DevOps, July ’15 - Feb ‘17 • AWS Solutions Architect Nov, 2011- Dec 2014 • Formerly on operations teams @Etsy and @Meetup • Little time at a hedge fund, Xerox and a few other startups – Rochester Institute of Technology: Applied Networking and Systems Administration ’05 – Internet infrastructure geek
  3. 3. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved https://secure.flickr.com/photos/mgifford/4525333972 Why are we here today?
  4. 4. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless means …
  5. 5. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless means … No servers to provision or manage Scales with usage Pay for value Availability and fault tolerance built in
  6. 6. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless means:
  7. 7. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless means: Greater agility Less overhead Better focus Increased scale More flexibility Faster time to market
  8. 8. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Today’s focus:
  9. 9. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Event-driven compute Functions as a service Serverless FaaS
  10. 10. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Lambda Handles
  11. 11. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Lambda release history LambdaPreview Announcement re:Invent2014 ? *As of October 2018, does not include region launches 2015 2016 2017 2018
  12. 12. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless applications Services (anything)Event source Function
  13. 13. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless applications Services (anything) Changes in data state Requests to endpoints Changes in resource state Event source Function
  14. 14. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless applications Services (anything) Changes in data state Requests to endpoints Changes in resource state Event source Function Node.js Python Java C# Go Ruby Runtime APINEW!
  15. 15. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved DEMO!
  16. 16. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Anatomy of a Lambda function Handler() function Function to be executed upon invocation Event object Data sent during Lambda function Invocation Context object Methods available to interact with runtime information (request ID, log group, more) public String handleRequest(Book book, Context context) { saveBook(book); return book.getName() + " saved!"; }
  17. 17. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Introducing: AWS Lambda runtime API and layers Features that allow developers to share, discover, and deploy both libraries and languages as part of their serverless applications Runtime API enables developers to use Lambda with any programming language. Layers let functions easily share code. Upload layer once, reference within any function. Layers promote separation of responsibilities, lets developers focus on writing business logic. Combined, runtime API and layers allow developers to share any programming language or language version with others NEW!
  18. 18. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Fine-grained pricing Buy compute time in 100ms increments Low request charge No hourly, daily, or monthly minimums No per-device fees Never pay for idle Free Tier 1M requests and 400,000 GBs of compute. Every month, every customer.
  19. 19. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Tweak your function’s computer power Lambda exposes only a memory control, with the % of CPU core and network capacity allocated to a function proportionally Is your code CPU, Network or memory-bound? If so, it could be cheaper to choose more memory.
  20. 20. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Smart resource allocation Match resource allocation (up to 3 GB!) to logic Stats for Lambda function that calculates 1000 times all prime numbers <= 1000000 128 MB 11.722965sec $0.024628 256 MB 6.678945sec $0.028035 512 MB 3.194954sec $0.026830 1024 MB 1.465984sec $0.024638 Green==Best Red==Worst
  21. 21. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Smart resource allocation Match resource allocation (up to 3 GB!) to logic Stats for Lambda function that calculates 1000 times all prime numbers <= 1000000 128 MB 11.722965sec $0.024628 256 MB 6.678945sec $0.028035 512 MB 3.194954sec $0.026830 1024 MB 1.465984sec $0.024638 Green==Best Red==Worst +$0.00001-10.256981sec
  22. 22. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Lambda execution model Synchronous (push) Amazon API Gateway AWS Lambda function /order Asynchronous (event) Amazon SNS AWS Lambda function Amazon S3 reqs Poll-based Amazon DynamoDB Amazon Kinesis changes AWS Lambda service function
  23. 23. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Lambda API 1. Lambda directly invoked via invoke API SDK clients Lambda function API provided by the Lambda service Used by all other services that invoke Lambda across all models Supports sync and async Can pass any event payload structure you want Client included in every SDK
  24. 24. Lambda permissions model Fine grained security controls for both execution and invocation: • Execution policies: • Define what AWS resources/API calls can this function access via IAM • Used in streaming invocations • E.g. “Lambda function A can read from DynamoDB table users” • Function policies: • Used for sync and async invocations • E.g. “Actions on bucket X can invoke Lambda function Z" • Resource policies allow for cross account access
  25. 25. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Common Lambda use cases Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit IT Automation • Policy engines • Extending AWS services • Infrastructure management
  26. 26. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Amazon API Gateway Create a unified API frontend for multiple micro- services Authenticate and authorize requests to a backend DDoS protection and throttling for your backend Throttle, meter, and monetize API usage by third- party developers
  27. 27. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Amazon API Gateway Internet Mobile apps Websites Services AWS Lambda functions AWS API Gateway Cache Endpoints on Amazon EC2 Amazon CloudWatch monitoring Amazon CloudFront Any other AWS service YOUR VPC Endpoints in Your VPC Regional API endpoints All publicly accessible endpoints AWS Lambda functions
  28. 28. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Introducing: API Gateway WebSockets Invoke AWS services like Lambda, Kinesis, or any HTTP endpoint based on message content Build real-time two-way communication applications chat, alerts and notifications, and streaming dashboards Fully managed APIs to handle connections and messages transfer between users and backend services Pay for what you use based on connection minutes and messages transferred Stateful connection Stateless connection Amazon API Gateway WebSockets API Public endpoints on Amazon EC2 Lambda functions Any other AWS service All publicly accessible endpoints Amazon Kinesis Mobile apps Chat AWS IoT devices Dashboards Coming soon!
  29. 29. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless web application with API Gateway API Gateway handles all your application routing. It can handle authentication and authorization, throttling, DDOS protection, and more. Amazon S3 API Gateway Lambda runs all the logic behind your website and interfaces with databases, other backend services, or anything else your site needs. AWS Lambda Amazon Simple Storage Service (Amazon S3) stores all of your static content: CSS, JS, images, and more. You would typically front this with a CDN such as CloudFront. Amazon CloudFront
  30. 30. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless architectures S3 bucket object Lambda function 1. File put into bucket 2. Lambda invoked Lambda function 2. Lambda invoked SNS topic 1. Data published to a topic Data 1. Message inserted into to a queue message Amazon SQS Lambda function 3. Function removes message from queue 2. Lambda polls queue and invokes function
  31. 31. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Serverless architectures Lambda function 2. Lambda polls stream Amazon Kinesis Data Stream 1. Data published to a stream 3. Amazon Kinesis returns stream data Data 2. Lambda invoked 1. Chatbot conversation needs “fulfillment” Lambda function Amazon Lex Chatbot Lambda function 1. Scheduled time occurs CloudWatch Events (time-based) 2. Lambda invoked
  32. 32. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Keep orchestration out of code
  33. 33. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS Step Functions “Serverless” workflow management with zero administration • Makes it easy to coordinate the components of distributed applications and microservices using visual workflows • Automatically triggers and tracks each step and retries when there are errors, so your application executes in order and as expected • Logs the state of each step, so when things do go wrong, you can diagnose and debug problems quickly Task Choice Failure capture Parallel tasks
  34. 34. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Build PCI and HIPAA compliant serverless applications! Serverless platform services that can be used in both: AWS Lambda Amazon S3 Amazon CloudFront Amazon DynamoDB Amazon Kinesis Data Streams Amazon Cognito Amazon API Gateway Amazon SNS
  35. 35. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Where do you ... https://secure.flickr.com/photos/stevendepolo/57491920?
  36. 36. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Start with a framework AWS Chalice
  37. 37. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved
  38. 38. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Metrics and logging are a universal right! • CloudWatch Metrics: • 7 Built in metrics for Lambda • Invocation Count, Invocation duration, Invocation errors, Throttled Invocation, Iterator Age, DLQ Errors, Concurrency • Can call “put-metric-data” from your function code for custom metrics • 7 Built in metrics for API-Gateway • API Calls Count, Latency, 4XXs, 5XXs, Integration Latency, Cache Hit Count, Cache Miss Count • Error and Cache metrics support averages and percentiles
  39. 39. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Metrics and logging are a universal right! • CloudWatch Logs: • API Gateway Logging • 2 Levels of logging, ERROR and INFO • Optionally log method request/body content • Set globally in stage, or override per method • Lambda Logging • Logging directly from your code with your language’s equivalent of console.log() • Basic request information included • Log Pivots • Build metrics based on log filters • Jump to logs that generated metrics • Export logs to AWS ElastiCache or S3 • Explore with Kibana or Athena/QuickSight
  40. 40. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved AWS X-Ray Integration with Serverless • Lambda instruments incoming requests for all supported languages and can capture calls made in code • API Gateway inserts a tracing header into HTTP calls as well as reports data back to X-Ray itself var AWSXRay = require(‘aws-xray-sdk-core‘); var AWS = AWSXRay.captureAWS(require(‘aws-sdk’)); S3Client = AWS.S3();
  41. 41. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved X-Ray Trace Example
  42. 42. DEMO!
  43. 43. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved aws.amazon.com/serverless
  44. 44. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved Chris Munns munns@amazon.com @chrismunnshttps://www.flickr.com/photos/theredproject/3302110152/
  45. 45. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved ? https://secure.flickr.com/photos/dullhunk/202872717/

×