O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Introduce AWS Lambda for newbie and Non-IT

138 visualizações

Publicada em

Introduce AWS Lambda for newbie and Non-IT

อธิบาย ความเป็นมาของ Serverless และ AWS Lambda คืออะไร ดีอย่างไร เพื่อให้คนไม่รู้จักและคนที่ไม่ใช่ IT ได้เข้าใจง่ายๆ

- What's Serverless
- What's AWS Lambda
- Working with AWS Lambda
- AWS Lambda Life-Cycle
- AWS Lambda Anatomy
- Beware Cold Start
- How to debug
- Do and Don't to implement
- Pricing structure and example
- Advantage/Disadvantage

Presentation is English Version
Blog is Thai Version : https://myifew.com/5166/understand-serverless-with-aws-lambda-for-newbie/

Publicada em: Tecnologia
  • Seja o primeiro a comentar

Introduce AWS Lambda for newbie and Non-IT

  1. 1. Introduce AWS Lambda By Chitpong Wuttanan (iFew) Updated as of 6 Feb 2019
  2. 2. Evolving to Serverless Reference: https://www.slideshare.net/AmazonWebServices/deep-dive-on-aws-lambda
  3. 3. Evolving to Serverless Reference: https://medium.com/@sdorzak/why-serverless-is-the-new-black-e4ff9e9947e0
  4. 4. What’s Serverless ● Is Cloud-computing execution model ● Dynamically manages the allocation of machine resources. ● Pricing is based on the actual amount of resources consumed by an application ● Execute application logic only, but do not store data ● Client side control flow and dynamic content generation replaces the server side controllers (Event-driven) ● In serverless applications, custom code components have a lifecycle that is much shorter ● Serverless Providers such as AWS Lambda, Google Cloud Functions, Microsoft Azure Functions, IBM/Apache's OpenWhisk (open source), Oracle Cloud Fn (open source) Reference: https://en.wikipedia.org/wiki/Serverless_computing, https://martinfowler.com/bliki/Serverless.html
  5. 5. What’s Serverless Reference: https://www.slideshare.net/AmazonWebServices/deep-dive-on-aws-lambda
  6. 6. Common use cases Reference: https://www.slideshare.net/AmazonWebServices/deep-dive-on-aws-lambda
  7. 7. What’s Lambda ● Serverless Computing platform for stateless as a part of the AWS (Amazon Web Services) ● Release on November 2014 (4 years agos) ● FaaS (Function-as-a-Service) ● Designed for EDA (Event-driven architecture) ● Support Node.js, Python, Java, Go, Ruby and C# through .NET Core ● Official Website https://aws.amazon.com/lambda ● Logo Reference: https://en.wikipedia.org/wiki/AWS_Lambda Lambda Lambda Function
  8. 8. Lambda Function Page Events Trigger Resources to access Function
  9. 9. AWS Lambda models Reference: https://www.slideshare.net/AmazonWebServices/deep-dive-on-aws-lambda
  10. 10. Working with AWS Lambda Reference: https://www.slideshare.net/AmazonWebServices/deep-dive-on-aws-lambda
  11. 11. Example: Request to API endpoint Reference: https://medium.com/@chrishantha/ballerina-services-in-serverless-world-b54c5e7382a0 Function
  12. 12. Understand the Function Lifecycle Reference: https://www.slideshare.net/AmazonWebServices/srv310designing-microservices-with-serverless
  13. 13. Reference: https://www.slideshare.net/AmazonWebServices/become-a-serverless-black-belt-optimizing-your-serverless-applications-srv401-reinvent-2017, https://www.slideshare.net/AmazonWebServices/srv310designing-microservices-with-serverless AWS Optimization Your Optimization Explain Initialization Beware the Cold Start
  14. 14. AWS Lambda Function anatomy Handler() Function Function to start execution of your Lambda function. Event object Data sent during Lambda function Context object Context object your code can interact with AWS Lambda
  15. 15. Continuous Scaling Reference: https://docs.aws.amazon.com/lambda/latest/dg/scaling.html Initial concurrency brust Concurrency Limit per Account Concurrency Limit Account 1,000 Start Concurrency (Asia Pacific - Singapore) 500 NumberofUserExecution 500 Add More (Automatic) per minute 500 0 1,000Increasingmoretraffic 1,000 * Can request an increase number of concurrent, Contact AWS 1,001+ Queue
  16. 16. Setup Rate Limiting with Reserve Concurrency Reserve concurrency for this function Concurrency limit per account Speed button, if execution count is exceeding Dynamic concurrency for this function (Default)
  17. 17. Function is Throttled Reserve concurrency to zero Can't call this function anyway
  18. 18. Error/Debugging Display
  19. 19. Access monitoring via AWS CloudWatch
  20. 20. Tracing via AWS X-Ray Duration time from Gateway Duration time from LambdaCold Start
  21. 21. Should doing for develop Lambda Function ● Separate the Lambda handler from your core logic. This allows you to make a more unit-testable function. ● Take advantage of Execution Context reuse to improve the performance of your function ● Use AWS Lambda Environment Variables to pass operational parameters to your function. ● Control the dependencies in your function's deployment package. ● Minimize your deployment package size to its runtime necessities. ● Reduce the time it takes Lambda to unpack deployment packages ● Minimize the complexity of your dependencies. ● Avoid using recursive code Reference: https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html#function-code
  22. 22. Should doing for develop Lambda Function ● Avoid fat/monolithic functions ● Performance Testing for your lambda, to allocate memory and control cost ● Load Test your Lambda function to determine an optimum timeout value and concurrency. ● Use most-restrictive permissions when setting IAM policies ● Delete Lambda functions that you are no longer using Reference: https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html#function-code
  23. 23. AWS Lambda Pricing Reference: https://aws.amazon.com/lambda/pricing/ Charged based on the number of requests for your functions and the duration time to execution code. * 1 Gigabyte second is 1 Gigabyte of memory used for one second.
  24. 24. AWS Lambda Pricing - What’s Request? Lambda counts a request each time it starts executing in response to an event notification or invoke call, including test invokes from the console. You are charged for the total number of requests across all your functions. Function1 Request to Reference: https://aws.amazon.com/lambda/pricing/
  25. 25. AWS Lambda Pricing - What’s Duration? Duration is calculated from the time your code begins executing until it returns or otherwise terminates, rounded up to the nearest 100ms. The price depends on the amount of memory you allocate to your function. Reference: https://aws.amazon.com/lambda/pricing/ Billed 15.2sec Actual 0.00208sec 15.1sec * 0.256 GB-Second = 3.8656 GB-Second 0.1sec * 0.128 GB-Second = 0.0128 GB-Second Billed 0.1sec Actual 15.18536sec * 1 Gigabyte second is 1 Gigabyte of memory used for one second.
  26. 26. Pricing related with Lambda Memory size Reference: https://aws.amazon.com/lambda/pricing/ Memory (MB) Free tier seconds per month Price per 100ms ($) 128 3,200,000 0.000000208 256 1,600,000 0.000000417 512 800,000 0.000000834 1024 400,000 0.000001667 2048 200,000 0.000003334 3008 136,170 0.000004897 Lambda Function use memory size 128GB and run 8 times equal 1 GB-Second. It’s mean Lambda Function can run 3,200,000 times/month (Free tier 400,000 GB-Second/month)
  27. 27. Pricing Example Reference: https://aws.amazon.com/lambda/pricing/ Function get_product() Allocate Memory Size 128mb Execute Duration 200ms 6,000,000 seconds Total execute in one month $5.83 Total charge in one month Compute charges 30 million times Total execute in one month $5.80 Total charge in one month Request charges Total charges = Compute charges + Request charges = $11.63 per month If you allocated 128MB of memory to your function, executed it 30 million times in one month, and it ran for 200ms each time, your charges would be calculated as follows:
  28. 28. Pricing Example What’s total compute number for free tier 128MB compute price is $0.000000208 per 100ms This function execute 200ms in 1 times is $0.000000417 or 1 times using 0.2sec * 128MB/1024 = 0.025 GB-s or 1 GB-s can run this function 40 times (or $0.00001667) Free tier 400,000 GB-s can run this function 16,000,000 times Calculate compute for 30 million times/month Total compute (seconds) = 30,000,000 * 0.2sec = 6,000,000 seconds Total compute (GB-s) = 6,000,000sec * 128MB/1024 = 750,000 GB-s 750,000 GB-s – 400,000 free tier GB-s = 350,000 GB-s Monthly compute charges = 350,000 * $0.00001667 = $5.83 Compute charges What’s total request number for free tier, and request cost - The monthly request price is $0.20 per 1 million requests - Free tier provides 1M requests per month. Calculate request for 30 million times/month Total requests – Free tier request = Billable requests 30M requests – 1M free tier requests = 29M Monthly billable requests Monthly request charges = 29M * $0.2/M = $5.80 Request charges
  29. 29. Advantages/Disadvantages ● Advantages ○ Significant reduction in costs ○ No servers to manage ○ Continuous Scaling ● Disadvantages ○ Infrequently-used serverless code may suffer from greater response latency (Start time to idle: 5 minutes) ○ Resource limits by cloud providers (Lambda Limit Concurrency 1,000/region/account) ○ Conceptual overhead of splitting a single application ○ Local development and unit testing is also harder ○ Hard to Monitoring and debugging ○ OS vulnerabilities are taken care of by the cloud provider Reference: https://en.wikipedia.org/wiki/Serverless_computing, https://martinfowler.com/bliki/Serverless.html, https://khasathan.in.th/archives/1712/