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.

以AWS Lambda與Amazon API Gateway打造無伺服器後端

3,469 views

Published on

AWS Lambda運算服務可運作程式碼,不需預備或管理伺服器,Amazon API Gateway為充分管理之服務,方便開發者發表、維護、監控及確保大小規模的API。

本 場次將說明AWS Lambda與Amazon API Gateway基本內容,並示範如何使用這些服務製作網路、行動與物聯網後端,講解如何設定API終端後,可啟動AWS Lambda功能,處理行動、網路、物聯網及第三方API需求。各位也將認識如何使用Lambda讀取及寫入Amazon DynamoDB,並設定簡易的無伺服器部落格網路應用程式,提供用戶驗證、新增文章、留言等功能。

Published in: Technology
  • Login to see the comments

以AWS Lambda與Amazon API Gateway打造無伺服器後端

  1. 1. AWS Cloud Kata for Start-Ups and Developers Taiwan Olivier Klein , Senior Solutions Architect, AWS Building Serverless Backends Using AWS Lambda and Amazon API Gateway
  2. 2. AWS Cloud Kata for Start-Ups and Developers How to build application backends? Back-end logic DatabaseMobile
  3. 3. AWS Cloud Kata for Start-Ups and Developers The familiar 3-Tier Architecture
  4. 4. AWS Cloud Kata for Start-Ups and Developers Dr. Werner Vogels CTO - Amazon
  5. 5. AWS Cloud Kata for Start-Ups and Developers No server is easier to manage…
  6. 6. AWS Cloud Kata for Start-Ups and Developers No server is easier to manage… …than no server.
  7. 7. AWS Cloud Kata for Start-Ups and Developers No server is easier to manage… …than no server. AWS Lambda
  8. 8. AWS Cloud Kata for Start-Ups and Developers Utilization Window Weeks Minutes Seconds Milliseconds On-Premise Amazon EC2 Containers AWS Lambda
  9. 9. AWS Cloud Kata for Start-Ups and Developers AWS Lambda: Run code in response to events Lambda functions: Stateless, trigger-based code execution Triggered by events: •  Direct and Asynchronous API calls •  AWS Service integrations •  3rd party triggers Makes it easy to: •  Perform event-driven actions •  Build back-end services that perform at scale
  10. 10. AWS Cloud Kata for Start-Ups and Developers Amazon S3 Amazon DynamoDB Amazon Kinesis AWS CloudFormation AWS CloudTrail Amazon CloudWatch Amazon SNS Amazon
 SES Amazon
 API Gateway Amazon Cognito AWS
 IoT Amazon
 Alexa Cron events DATA STORES ENDPOINTS REPOSITORIES EVENT/MESSAGE SERVICES Event Sources that integrate with AWS Lambda … and the list continues to grow.
  11. 11. AWS Cloud Kata for Start-Ups and Developers Multiple Application Types using AWS Lambda   Analytics •  Operational management •  Live Dashboards   Data workflows •  Content management •  ETL workflows   Interactive Backends •  Bots •  Webhooks   Autonomous IT •  Policy engines •  Infrastructure management
  12. 12. AWS Cloud Kata for Start-Ups and Developers The Other Challenge..
  13. 13. AWS Cloud Kata for Start-Ups and Developers Managing APIs is Hard! Managing multiple versions and stages of an API is difficult Monitoring 3rd party developers’ access is time consuming Access authorization is a challenge Traffic spikes create operational burden
  14. 14. AWS Cloud Kata for Start-Ups and Developers API Gateway to manage your REST endpoints   Build, Deploy and Manage APIs   Throttling rules per HTTP method   Cache with customizable keys   Multiple API version and stages   Generates client SDKs   Dashboard for visual monitoring   Flexible authorization model   Usage plans for consumption
  15. 15. AWS Cloud Kata for Start-Ups and Developers API Gateway + Lambda = Frontend + Backend Endpoints on Amazon EC2 Any other publicly accessible endpoint AWS Lambda functions API Gateway Cache Internet Mobile Apps Websites Services Amazon CloudFront Amazon API Gateway Amazon CloudWatch Monitoring
  16. 16. AWS Cloud Kata for Start-Ups and Developers DDoS and Network Protection Internet Mobile Apps Websites Services AWS Lambda functions Endpoints on Amazon EC2 Amazon CloudFront Amazon API Gateway Layer 7 and layer 3 DDoS protection Request throttling for backend services
  17. 17. AWS Cloud Kata for Start-Ups and Developers Attaching Lambda functions to RESTful HTTP Endpoints   1:1 Mapping - Every API call triggers a stateless Lambda function •  Add caching to API calls to return a cached response instead for duplicate requests   API Gateway Concepts - API defined as a set of resources and methods •  Resource: A logical entity that can be accessed within an API •  Method: Resource path and an HTTP command such as GET/POST   Automatic Scaling – API Gateway and Lambda scale automatically •  Safety throttle of 100 concurrent Lambda functions, can be increased by AWS Support •  User defined standard-rate limit and a burst-rate limit per second for each API method
  18. 18. AWS Cloud Kata for Start-Ups and Developers AWS Lambda Hello World API Amazon API Gateway Python (Chalice) Postman DEMO Test Build / Deploy
  19. 19. AWS Cloud Kata for Start-Ups and Developers Web App
  20. 20. AWS Cloud Kata for Start-Ups and Developers Real World Architecture
  21. 21. AWS Cloud Kata for Start-Ups and Developers Real World “Serverless” Architecture
  22. 22. AWS Cloud Kata for Start-Ups and Developers Storage and Delivery of the App Amazon S3 Amazon CloudFront   Amazon S3 •  Highly available object storage •  Designed for 99.999999999% durability •  Offers HTTP / HTTPS endpoint to objects   Amazon CloudFront •  Content Delivery Network with 59 edge locations across the world •  Caches content on edge locations for low latency
  23. 23. AWS Cloud Kata for Start-Ups and Developers Swagger
  24. 24. AWS Cloud Kata for Start-Ups and Developers Swagger!   Swagger •  Goal is to define a language-agnostic interface to REST APIs •  Ecosystem of tools to explore, visualize, document and test APIs SwaggerHub •  Collaborative platform to define and manage APIs •  Integration with Amazon API Gateway www.swagger.io
  25. 25. AWS Cloud Kata for Start-Ups and Developers Swagger – Build an API in minutes! Amazon API Gateway Swagger DEMO AWS Lambda Function AWS Lambda Function
  26. 26. AWS Cloud Kata for Start-Ups and Developers NLTK & Lambda   NLTK is a toolkit written in Python to facilitate Natural Language Processing (NLP)   Provides easy-to-use interfaces for classification, tokenization, stemming, tagging, parsing, and semantic reasoning   VADER - Rule-based Model for Sentiment Analysis of Social Media Text www.nltk.org
  27. 27. AWS Cloud Kata for Start-Ups and Developers Amazon S3 Sentiment Analysis Web App Amazon API Gateway Amazon Route 53 HTML / JS / CSS Swagger www.aws.klein.asia api.aws.klein.asia DEMO
  28. 28. AWS Cloud Kata for Start-Ups and Developers Best Practices
  29. 29. AWS Cloud Kata for Start-Ups and Developers Best Practices for Lambda functions   Memory •  CPU proportional to memory •  Increasing =memory makes your code execute faster (if CPU bound)   Timeout •  Increasing timeout allows for longer functions, but more wait in case of errors   Retries •  For API Gateway, Lambda doesn’t retry the function execution if failed •  Gateway generated SDKs retry throttled requests   Permission Model •  API Gateway synchronously triggers Lambda, so assign API Gateway a resource policy to invoke Lambda
  30. 30. AWS Cloud Kata for Start-Ups and Developers Using API Gateway Input/Output Transforms   Filter Output Results •  Remove private/unnecessary data •  Filter dataset size to improve API performance   Translate between client and backend •  Convert GET query strong parameters to body for POST •  Talk XML to API user-interface but JSON to Lambda
  31. 31. AWS Cloud Kata for Start-Ups and Developers Managing different versions of your API stack   Operate multiple API versions and multiple stages for each version simultaneously   Clone an existing API to start working on the next major version   Set up custom domain names to point directly to a stage   Version Lambda functions, and associate API stage with Lambda function version alias
  32. 32. AWS Cloud Kata for Start-Ups and Developers Final Thoughts   Plug-in API Gateway early. It allows to split your API between legacy EC2 and new Lambda functions   Create many version and stages – no additional charges for APIs, allows for backwards compatibility   Document your API from Day 1   Test your API calls consistently and automatically   Always use serverless interfaces when possible – HTML5 and JS frameworks like React or Angular are useful
  33. 33. AWS Cloud Kata for Start-Ups and Developers Thank you! Olivier Klein Senior Solutions Architect AWS

×