SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SRV301 - Best Practices for using
AWS Lambda with RDS-RDBMS
solutions
Mayank Thakkar
Global Life Sciences Solutions Architect
AWS
S R V 3 0 1
Emma Zhao
Software Development Manager
AWS
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Typical Solution Architecture
AWS Cloud
VPC
Availability zone 1
Availability zone 2
Private subnet
Private subnet
Private subnet
Private subnet
DB Instance
DB instance
standby
Elastic
network
interface
Elastic
network
interface
Lambda
Functions
Security group Security group
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Lambda with RDS / RDBMS - Best Practices
• Use subnets in multiple AZs for ENI configuration
• Protects against AZ failure and IP address exhaustion
• Lambda relies on ENIs (within your VPC) to connect
• Scalability depends on available free IP addresses and ENI limits
• ENI startup penalty
• Lambda in VPC mode does not have internet access by default.
• Add Network Address Translation (NAT) gateway inside the VPC to
enable internet access
• Avoid DNS resolution of public host names if possible
• Adds billable, time consuming resolution.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Problem: Managing Database Connections
…
Lambda can scale, can your database connections?
Is Connection
pooling the answer?
Generic database
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Time
Container A
Container B
Container C
Container D
Lambda - Scaling
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How does that affect Connection Pooling?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Connection Pooling with Lambda
Use only one connection in a container, at a time
Set Connection Pool Size = 1
OR
Initialize the connection object “above the handler”
(in the global section)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Connection Pooling with Lambda - Challenges
• No hook to indicate destruction of Lambda containers
• Can not explicitly close connections when the container is
recycled
• Fall back on Database TTL to clean up connections
• Can lead to session leakages
• No control over lifecycle of Lambda containers
• Can result many connections sitting idle
• Different containers for different Lambda functions
• No re use of connections across Lambda functions
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, 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*
* - Only for asynchronous and stream based event sources.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Solution 1b: Function Concurrency Limit
Lambda can help
with retries of
throttled
invocations*
* - Only for asynchronous and stream based event sources.
© 2018, 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 function level.
• Simple to set up
• Account level limit requires AWS support
• AWS Lambda manages retries for throttled
invocations*
© 2018, 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
• Can not spread out connections dynamically, as load across
Lambdas varies
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Dynamic Connection Management
Helper
Maintain atomic counter
and max count
Open / close
connections
DB operations
Do something interesting
Generic database
Alarm
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Demo Code: https://tinyurl.com/lambdards
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Dynamic Connection Management - Benefits
• Scalable solution : depends on Lambda and Amazon DynamoDB
• Connections count managed from DB perspective
No limit on number of Lambda functions
• Can spread DB connections across Lambda functions @ 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
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Dynamic Connection Management - Challenges
• No retries of throttled invocations: requires custom solution.
• More resources to manage.
• No connection re-use.
• Slightly increased latency.
© 2018, 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
• Solutions and Best Practices:
• Account and function level concurrency Limits
• Custom Solution: Dynamic Connection Management
© 2018, 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://tinyurl.com/lambdards
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Questions?
Demo Code: https://tinyurl.com/lambdards
Thank you!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Mayank Thakkar
Global Life Sciences Solutions Architect
AWS
Emma Zhao
Software Development Manager
AWS
Demo Code: https://tinyurl.com/lambdards
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Mais conteúdo relacionado

Mais procurados

강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...
강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...
강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...
Amazon Web Services Korea
 
AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...
AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...
AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...
Simplilearn
 

Mais procurados (20)

AWS - Security & Compliance
AWS - Security & ComplianceAWS - Security & Compliance
AWS - Security & Compliance
 
AWS Tagging Strategy
AWS Tagging StrategyAWS Tagging Strategy
AWS Tagging Strategy
 
강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...
강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...
강의 3. AWS 보안 및 AWS Identity and Access Managment (IAM)::AWSome Day Online Con...
 
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
 
Fundamentals of AWS Security
Fundamentals of AWS SecurityFundamentals of AWS Security
Fundamentals of AWS Security
 
SRV403_Serverless Authentication and Authorization
SRV403_Serverless Authentication and AuthorizationSRV403_Serverless Authentication and Authorization
SRV403_Serverless Authentication and Authorization
 
AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...
AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...
AWS S3 | Tutorial For Beginners | AWS S3 Bucket Tutorial | AWS Tutorial For B...
 
Protecting Your Data- AWS Security Tools and Features
Protecting Your Data- AWS Security Tools and FeaturesProtecting Your Data- AWS Security Tools and Features
Protecting Your Data- AWS Security Tools and Features
 
Amazon S3 & Amazon Glacier - Object Storage Overview
Amazon S3 & Amazon Glacier - Object Storage OverviewAmazon S3 & Amazon Glacier - Object Storage Overview
Amazon S3 & Amazon Glacier - Object Storage Overview
 
AWS Route53
AWS Route53AWS Route53
AWS Route53
 
Designing security & governance via AWS Control Tower & Organizations - SEC30...
Designing security & governance via AWS Control Tower & Organizations - SEC30...Designing security & governance via AWS Control Tower & Organizations - SEC30...
Designing security & governance via AWS Control Tower & Organizations - SEC30...
 
금융 서비스 패러다임의 전환 가속화 시대, 신한금융투자의 Cloud First 전략 - 신중훈 AWS 솔루션즈 아키텍트 / 최성봉 클라우...
금융 서비스 패러다임의 전환 가속화 시대, 신한금융투자의 Cloud First 전략  - 신중훈 AWS 솔루션즈 아키텍트 / 최성봉 클라우...금융 서비스 패러다임의 전환 가속화 시대, 신한금융투자의 Cloud First 전략  - 신중훈 AWS 솔루션즈 아키텍트 / 최성봉 클라우...
금융 서비스 패러다임의 전환 가속화 시대, 신한금융투자의 Cloud First 전략 - 신중훈 AWS 솔루션즈 아키텍트 / 최성봉 클라우...
 
AWS Lake Formation Deep Dive
AWS Lake Formation Deep DiveAWS Lake Formation Deep Dive
AWS Lake Formation Deep Dive
 
Amazon Route 53 - Webinar Presentation 9.16.2015
Amazon Route 53 - Webinar Presentation 9.16.2015Amazon Route 53 - Webinar Presentation 9.16.2015
Amazon Route 53 - Webinar Presentation 9.16.2015
 
AWS glue technical enablement training
AWS glue technical enablement trainingAWS glue technical enablement training
AWS glue technical enablement training
 
Building a Scalable Digital Asset Management Platform in the Cloud (MED402) |...
Building a Scalable Digital Asset Management Platform in the Cloud (MED402) |...Building a Scalable Digital Asset Management Platform in the Cloud (MED402) |...
Building a Scalable Digital Asset Management Platform in the Cloud (MED402) |...
 
Introduction to Amazon Athena
Introduction to Amazon AthenaIntroduction to Amazon Athena
Introduction to Amazon Athena
 
Introduction to Amazon Athena
Introduction to Amazon AthenaIntroduction to Amazon Athena
Introduction to Amazon Athena
 
AWS Summit Seoul 2023 | 삼성전자/쿠팡의 대규모 트래픽 처리를 위한 클라우드 네이티브 데이터베이스 활용
AWS Summit Seoul 2023 | 삼성전자/쿠팡의 대규모 트래픽 처리를 위한 클라우드 네이티브 데이터베이스 활용AWS Summit Seoul 2023 | 삼성전자/쿠팡의 대규모 트래픽 처리를 위한 클라우드 네이티브 데이터베이스 활용
AWS Summit Seoul 2023 | 삼성전자/쿠팡의 대규모 트래픽 처리를 위한 클라우드 네이티브 데이터베이스 활용
 
AWS Summit Seoul 2023 | 데이터, 분석 및 AI를 통합하는 단 하나의 레이크하우스, Databricks on AWS 로 ...
AWS Summit Seoul 2023 | 데이터, 분석 및 AI를 통합하는 단 하나의 레이크하우스, Databricks on AWS 로 ...AWS Summit Seoul 2023 | 데이터, 분석 및 AI를 통합하는 단 하나의 레이크하우스, Databricks on AWS 로 ...
AWS Summit Seoul 2023 | 데이터, 분석 및 AI를 통합하는 단 하나의 레이크하우스, Databricks on AWS 로 ...
 

Semelhante a Best Practices for Using AWS Lambda with RDS/RDBMS Solutions (SRV301-R1) - AWS re:Invent 2018

Serverless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best PracticesServerless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best Practices
Amazon Web Services
 

Semelhante a Best Practices for Using AWS Lambda with RDS/RDBMS Solutions (SRV301-R1) - AWS re:Invent 2018 (20)

Serverless use cases with AWS Lambda - More Serverless Event
Serverless use cases with AWS Lambda - More Serverless EventServerless use cases with AWS Lambda - More Serverless Event
Serverless use cases with AWS Lambda - More Serverless Event
 
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
 
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
 
Serverless Architectural Patterns: Collision 2018
Serverless Architectural Patterns: Collision 2018Serverless Architectural Patterns: Collision 2018
Serverless Architectural Patterns: Collision 2018
 
Serverless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best PracticesServerless Architecture - Design Patterns and Best Practices
Serverless Architecture - Design Patterns and Best Practices
 
Scale up a Web Application (ARC409-R) - AWS re:Invent 2018
Scale up a Web Application (ARC409-R) - AWS re:Invent 2018Scale up a Web Application (ARC409-R) - AWS re:Invent 2018
Scale up a Web Application (ARC409-R) - AWS re:Invent 2018
 
SRV315 Building Enterprise-Grade Serverless Apps
 SRV315 Building Enterprise-Grade Serverless Apps SRV315 Building Enterprise-Grade Serverless Apps
SRV315 Building Enterprise-Grade Serverless Apps
 
Serverless SaaS apllications on AWS
Serverless SaaS apllications on AWSServerless SaaS apllications on AWS
Serverless SaaS apllications on AWS
 
Become a Serverless Black Belt - Optimizing Your Serverless Applications - AW...
Become a Serverless Black Belt - Optimizing Your Serverless Applications - AW...Become a Serverless Black Belt - Optimizing Your Serverless Applications - AW...
Become a Serverless Black Belt - Optimizing Your Serverless Applications - AW...
 
All the Ops you need to know to Dev Serverless
All the Ops you need to know to Dev ServerlessAll the Ops you need to know to Dev Serverless
All the Ops you need to know to Dev Serverless
 
AWS Lambda use cases and best practices - Builders Day Israel
AWS Lambda use cases and best practices - Builders Day IsraelAWS Lambda use cases and best practices - Builders Day Israel
AWS Lambda use cases and best practices - Builders Day Israel
 
Serverless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about serversServerless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about servers
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural Patterns
 
Ci/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO ClubCi/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO Club
 
Serverless on AWS: Architectural Patterns and Best Practices
Serverless on AWS: Architectural Patterns and Best PracticesServerless on AWS: Architectural Patterns and Best Practices
Serverless on AWS: Architectural Patterns and Best Practices
 
Serverless Computing: build and run applications without thinking about servers
Serverless Computing: build and run applications without thinking about serversServerless Computing: build and run applications without thinking about servers
Serverless Computing: build and run applications without thinking about servers
 
Microservices & Data Design
Microservices & Data DesignMicroservices & Data Design
Microservices & Data Design
 
Microservices & Data Design: Database Week SF
Microservices & Data Design: Database Week SFMicroservices & Data Design: Database Week SF
Microservices & Data Design: Database Week SF
 
Microservices and Data Design
Microservices and Data DesignMicroservices and Data Design
Microservices and Data Design
 
Microservices & Data Design: Database Week San Francisco
Microservices & Data Design: Database Week San FranciscoMicroservices & Data Design: Database Week San Francisco
Microservices & Data Design: Database Week San Francisco
 

Mais de Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

Mais de Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Best Practices for Using AWS Lambda with RDS/RDBMS Solutions (SRV301-R1) - AWS re:Invent 2018

  • 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. SRV301 - Best Practices for using AWS Lambda with RDS-RDBMS solutions Mayank Thakkar Global Life Sciences Solutions Architect AWS S R V 3 0 1 Emma Zhao Software Development Manager AWS
  • 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Typical Solution Architecture AWS Cloud VPC Availability zone 1 Availability zone 2 Private subnet Private subnet Private subnet Private subnet DB Instance DB instance standby Elastic network interface Elastic network interface Lambda Functions Security group Security group
  • 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Lambda with RDS / RDBMS - Best Practices • Use subnets in multiple AZs for ENI configuration • Protects against AZ failure and IP address exhaustion • Lambda relies on ENIs (within your VPC) to connect • Scalability depends on available free IP addresses and ENI limits • ENI startup penalty • Lambda in VPC mode does not have internet access by default. • Add Network Address Translation (NAT) gateway inside the VPC to enable internet access • Avoid DNS resolution of public host names if possible • Adds billable, time consuming resolution.
  • 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Problem: Managing Database Connections … Lambda can scale, can your database connections? Is Connection pooling the answer? Generic database
  • 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Time Container A Container B Container C Container D Lambda - Scaling
  • 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How does that affect Connection Pooling?
  • 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Connection Pooling with Lambda Use only one connection in a container, at a time Set Connection Pool Size = 1 OR Initialize the connection object “above the handler” (in the global section)
  • 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Connection Pooling with Lambda - Challenges • No hook to indicate destruction of Lambda containers • Can not explicitly close connections when the container is recycled • Fall back on Database TTL to clean up connections • Can lead to session leakages • No control over lifecycle of Lambda containers • Can result many connections sitting idle • Different containers for different Lambda functions • No re use of connections across Lambda functions
  • 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 13. © 2018, 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* * - Only for asynchronous and stream based event sources.
  • 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Solution 1b: Function Concurrency Limit Lambda can help with retries of throttled invocations* * - Only for asynchronous and stream based event sources.
  • 15. © 2018, 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 function level. • Simple to set up • Account level limit requires AWS support • AWS Lambda manages retries for throttled invocations*
  • 16. © 2018, 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 • Can not spread out connections dynamically, as load across Lambdas varies
  • 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Dynamic Connection Management Helper Maintain atomic counter and max count Open / close connections DB operations Do something interesting Generic database Alarm
  • 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Demo Code: https://tinyurl.com/lambdards
  • 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Dynamic Connection Management - Benefits • Scalable solution : depends on Lambda and Amazon DynamoDB • Connections count managed from DB perspective No limit on number of Lambda functions • Can spread DB connections across Lambda functions @ 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
  • 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Dynamic Connection Management - Challenges • No retries of throttled invocations: requires custom solution. • More resources to manage. • No connection re-use. • Slightly increased latency.
  • 22. © 2018, 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 • Solutions and Best Practices: • Account and function level concurrency Limits • Custom Solution: Dynamic Connection Management
  • 23. © 2018, 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://tinyurl.com/lambdards
  • 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Questions? Demo Code: https://tinyurl.com/lambdards
  • 25. Thank you! © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mayank Thakkar Global Life Sciences Solutions Architect AWS Emma Zhao Software Development Manager AWS Demo Code: https://tinyurl.com/lambdards
  • 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.