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.

Best Practices for using AWS Lambda with RDS-RDBMS Solutions (SRV320)

4,861 views

Published on

Are you considering using AWS Lambda with your RDS/RDBMS solutions, but don’t know where to start? In this session, we look at recommended architectural patterns and best practices around using RDS/RDBMS solutions with Lambda functions. We also discuss migration steps, covering migration from on-premises RDBMS solutions to AWS serverless infrastructure (keeping the same RDBMS application model). Come and join our discussion, ask questions, and learn more about using Lambda with RDS/RDBMS solutions.

Published in: Technology

Best Practices for using AWS Lambda with RDS-RDBMS Solutions (SRV320)

  1. 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS re:INVENT Best Practices for Using AWS Lambda with RDS/RDBMS Solutions M a y a n k T h a k k a r , H C L S S o l u t i o n s A r c h i t e c t E m m a Z h a o , S o f t w a r e D e v e l o p m e n t M a n a g e r , L a m b d a D e c e m b e r 1 , 2 0 1 7 S R V 3 2 0
  2. 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Problem: Managing database connections … AWS Lambda can scale, can your database connections? Is connection pooling the answer?
  3. 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda: The scaling background
  4. 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Time Container A Container B Container C Container D Lambda—scaling
  5. 5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. How does that affect connection pooling?
  6. 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Connection pooling with Lambda • Only one connection is used at a time in a container • Connection pool size = 1 • Just initialize a connection object in the global section of Lambda and use that connection OR
  7. 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Connection pooling with Lambda —challenges • No hook to indicate destruction of Lambda containers • Cannot explicitly close connections when the container is recycled • Fall back on database TTL to clean up connections • No control over lifecycle of Lambda containers • Can result in many connections sitting idle • Different containers for different Lambda functions • No reuse of connections across Lambda functions
  8. 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Managing concurrency
  9. 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Solution 1 Set concurrency limits
  10. 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Solution 1a: Account concurrency limit Use AWS Organizations to manage your accounts AWS account Lambda can help with retries of throttled invocations* *Refer to references section for details
  11. 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Solution 1b: Function concurrency limit Lambda can help with retries of throttled invocations* *Refer to references section for details
  12. 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Concurrency limits—benefits • Lambda concurrency limit can be set at the account level or at the function level • Simple to set up • Account level limit requires AWS support • AWS Lambda manages retries for throttled invocations*
  13. 13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Concurrency limits—challenges • Account level limit: • Covers Lambdas across the account—difficult to isolate DB interfacing functions • Possibility of accounts sprawl • Function level limit: • Prior knowledge of DB accessing functions required • Limit should correspond to peak concurrency—prior application behavior knowledge required • Cannot spread out connections dynamically because load across Lambdas varies
  14. 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Solution 2 Dynamic connection management c u s t o m s o l u t i o n
  15. 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Dynamic connection management Amazon DynamoDB Helper Maintain atomic counter and max count Open/close connections DB operations Amazon CloudWatch CloudWatch AlarmDo something interesting
  16. 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Dynamic connection management Demo
  17. 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Benefits • Scalable solution: depends on Lambda and DynamoDB • Connections count managed from DB perspective • No limit on number of Lambda functions • Can spread DB connections across Lambda functions at runtime • Eliminate choke points and better serve hotspots • Easy update: control usable connections count through DynamoDB • Use published CloudWatch metrics to react to out-of-connection errors
  18. 18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Challenges • No retries of throttled invocations: requires custom solution • More resources to manage • No connection reuse • Slightly increased latency
  19. 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Summary • Lambda scaling model and connection pooling do not mix • Use a single connection, initialized in the global section • Manage concurrency using: • Account and function level concurrency Limits • Custom solution: dynamic connection management
  20. 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. References • AWS organizations • https://aws.amazon.com/organizations/ • AWS serverless : • https://aws.amazon.com/serverless/ • AWS Lambda container reuse: • https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/ • Lambda—retries of throttled invocations: • http://docs.aws.amazon.com/lambda/latest/dg/concurrent- executions.html#concurrent-execution-safety-limit • Dynamic connections manager sample code: • https://github.com/awslabs/LambdaRDS-ManageConnections
  21. 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Questions
  22. 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank you!

×