deep dive on aws lambda

Download Deep Dive on AWS Lambda

Post on 21-Jan-2018

1.107 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  1. 1. Deep Dive on AWS Lambda Heitor Lessa, Solutions Architect, AWS Serverless
  2. 2. About me Heitor Lessa Developer Technologies Amazon Web Services 10 years of sysadmin, networking and systems architecture background. AWS User since 2011 then joined AWS in 2013 Go by Bob on Starbucks Python/Node Twitter: @heitor_lessa Email: lessa@amazon.com
  3. 3. What to expect from todays webinar Fundamentals of AWS Lambda Authoring functions and AWS Lambda environment ALM for AWS Lambda Debugging and operations for AWS Lambda Questions & answers
  4. 4. What NOT to expect from todays webinar Deep dive on CI/CD for Serverless applications Deep dive on Serverless platform Amazon API Gateway Amazon DynamoDB AWS Lambda@Edge AWS Step Functions AWS X-Ray, etc. Deep dive on Best Practices
  5. 5. Virtual Servers in the Cloud Physical Servers in Datacenters Virtual Servers in Datacenters Containers in the Cloud Serverless with the Cloud Evolving to Serverless
  6. 6. A serverless world No servers to provision or manage Scales with usage Never pay for idle Availability and fault tolerance built in
  7. 7. Customers
  8. 8. Common use cases for Serverless Applications 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 Autonomous IT Policy engines Extending AWS services Infrastructure management
  9. 9. Fundamentals of AWS Lambda
  10. 10. 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 GB-s of compute. Every month, every customer.
  11. 11. Working with AWS Lambda EVENT SOURCE FUNCTION SERVICES (ANYTHING) Changes in data state Requests to endpoints Changes in resource state Node Python Java C# more coming soon
  12. 12. Lambda execution model Synchronous (push) Asynchronous (event) Stream-based Amazon API Gateway AWS Lambda function Amazon DynamoDBAmazon SNS /order AWS Lambda function Amazon S3 reqs Amazon Kinesis changes AWS Lambda service function
  13. 13. Amazon S3 Amazon DynamoDB Amazon Kinesis AWS CloudFormation AWS CloudTrail Amazon CloudWatch Amazon SNSAmazon SES Amazon API Gateway Amazon Cognito Amazon Alexa Cron events DATA STORES ENDPOINTS REPOSITORIES EVENT/MESSAGE SERVICES Event Sources that integrate with AWS Lambda and the list will continue to grow! Amazon RDS Aurora AWS Step Functions ORCHESTRATION AND STATE MANAGEMENT AWS IoT
  14. 14. Monitoring and debugging Lambda Functions AWS Lambda console includes a dashboard for functions Lists all Lambda functions Easy editing of resources, event sources and other settings At-a-glance metrics Metrics automatically reported to Amazon CloudWatch for each Lambda function Requests Errors Latency Throttles Logs captured by Amazon CloudWatch Logging service
  15. 15. Authoring functions and AWS Lambda environment
  16. 16. 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, etc.) s3 = boto3.resource('s3') app = App() def lambda_handler(event, context): # do something ...
  17. 17. The execution environment Amazon Linux Compile native binaries against Lambda AMI Test using exact version of libraries available Always package own SDKs/Libraries within functions docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html
  18. 18. ALM for AWS Lambda
  19. 19. CI/CD Code*, Cloudformation and SAM MonitorProvisionDeployTestBuildCode Cloud WatchCloud Formation Code Commit CodePipeline CodeBuild X-Ray
  20. 20. Frameworks Chalice aws.amazon.com/serverless/developer-tools
  21. 21. Local development with SAM Local (Beta) Test functions locally via Docker containers Run API Gateway locally with hot-reloading Validate SAM templates Support for local debugging NEW! awslabs/aws-sam-local
  22. 22. Debugging and operations for AWS Lambda
  23. 23. X-Ray service
  24. 24. X-Ray Application Insights
  25. 25. X-Ray Application Insights
  26. 26. X-Ray Application Insights
  27. 27. Application instrumentation (Node.js)
  28. 28. Build an App with AWS CodeStar and receive $50 in AWS Credits Register using the link below to receive AWS Credits* 1 Click the tweet icon in the console to share your app on Twitter 2 Build your app in the AWS CodeStar console 3 * Amazon Web Services (AWS) Promotional Credits will be awarded once per user for a limited time only upon successful completion of the challenge. $50 in AWS Promotional Credits will be awarded via email within 10-12 days of submission and are valid until December 31, 2018. Customers are limited to having two promotional credits on their AWS account at a given time. Go to https://aws.amazon.com/codestar/codestar-credit-challenge/ for details
  29. 29. Thank you!
  30. 30. Appendix
  31. 31. AWS Lambda limits Resource Limits Default Limit Ephemeral disk capacity ("/tmp" space) 512 MB Number of file descriptors 1024 Number of processes and threads (combined total) 1024 Maximum execution duration per request 300 seconds Invoke request body payload size (RequestResponse) 6 MB Invoke request body payload size (Event) 128 K Invoke response body payload size (RequestResponse) 6 MB Dead-letter payload size (Event) 128 K Deployment Limits Default Limit Lambda function deployment package size (.zip/.jar file) 50 MB Size of code/dependencies that you can zip into a deployment package (uncompressed zip/jar size) 250 MB Total size of all the deployment packages that can be uploaded per region 75 GB Total size of environment variables set 4 KB Throttling Limits (can request service limit increase) Default Limit Concurrent executions 1000 NEW!
  32. 32. The push model and resource policies Function (resource) policy Permissions you grant to your Lambda function determine which service or event source can invoke your function Resource policies make it easy to grant cross-account permissions to invoke your Lambda function
  33. 33. The pull model and IAM roles IAM (execution) role Permissions you grant to this role determine what your AWS Lambda function can do If event source is Amazon DynamoDB or Amazon Kinesis, then add read permissions in IAM role
  34. 34. Building blocks for serverless applications AWS Lambda Amazon DynamoDB Amazon SNS Amazon API Gateway Amazon SQS Amazon Kinesis Amazon S3 Orchestration and State Management API Proxy Messaging and Queues Analytics Monitoring and Debugging Compute Storage Database AWS X-RayAWS Step Functions
  35. 35. Testing strategies Run Unit tests locally Run Integration/Acceptance tests with real services Leverage Lambda Runtime AMI
  36. 36. Separate business logic from function signature app = Todo() def lambda_handler(event, context): ret = app.dispatch(event) return { 'statusCode': ret["status_code"], 'headers': ret["headers"], 'body': json.dumps(ret["body"]) }
  37. 37. Cloudwatch Metrics and streaming Leverage built-in metrics and alarm on aggregated (throttling ) Create Custom Metrics via Metric Filter out of logs Stream and centralize logs from multiple accounts to Amazon ElasticSearch for near real-time analysis Use X-Ray to drill down application insights built-in custom Amazon Cloudwatch
  38. 38. Compute power: Dont guesstimate alexcasalboni aws-lambda-power-tuning