SlideShare a Scribd company logo
1 of 26
Download to read 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.

More Related Content

What's hot

[AWSマイスターシリーズ]Identity and Access Management (IAM)
[AWSマイスターシリーズ]Identity and Access Management (IAM)[AWSマイスターシリーズ]Identity and Access Management (IAM)
[AWSマイスターシリーズ]Identity and Access Management (IAM)Amazon Web Services Japan
 
Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...
Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...
Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...Amazon Web Services
 
20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンス
20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンス20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンス
20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンスAmazon Web Services Japan
 
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...Amazon Web Services
 
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기Amazon Web Services Korea
 
Introducing AWS Firewall Manager - AWS Online Tech Talks
Introducing AWS Firewall Manager - AWS Online Tech TalksIntroducing AWS Firewall Manager - AWS Online Tech Talks
Introducing AWS Firewall Manager - AWS Online Tech TalksAmazon Web Services
 
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...Amazon Web Services Korea
 
Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...
Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...
Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...Amazon Web Services
 
Black Belt Online Seminar AWS上の暗号化ソリューション
Black Belt Online Seminar AWS上の暗号化ソリューションBlack Belt Online Seminar AWS上の暗号化ソリューション
Black Belt Online Seminar AWS上の暗号化ソリューションAmazon Web Services Japan
 
(STG401) Amazon S3 Deep Dive & Best Practices
(STG401) Amazon S3 Deep Dive & Best Practices(STG401) Amazon S3 Deep Dive & Best Practices
(STG401) Amazon S3 Deep Dive & Best PracticesAmazon Web Services
 
AWS Security Week: AWS Secrets Manager
AWS Security Week: AWS Secrets ManagerAWS Security Week: AWS Secrets Manager
AWS Security Week: AWS Secrets ManagerAmazon Web Services
 
AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기
AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기
AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기Amazon Web Services Korea
 
Identity and Access Management: The First Step in AWS Security
Identity and Access Management: The First Step in AWS SecurityIdentity and Access Management: The First Step in AWS Security
Identity and Access Management: The First Step in AWS SecurityAmazon Web Services
 
20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced Session
20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced Session20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced Session
20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced SessionAmazon Web Services Japan
 
(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIs
(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIs(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIs
(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIsAmazon Web Services
 
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.2015Amazon Web Services
 

What's hot (20)

[AWSマイスターシリーズ]Identity and Access Management (IAM)
[AWSマイスターシリーズ]Identity and Access Management (IAM)[AWSマイスターシリーズ]Identity and Access Management (IAM)
[AWSマイスターシリーズ]Identity and Access Management (IAM)
 
Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...
Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...
Behind the Scenes: Exploring the AWS Global Network (NET305) - AWS re:Invent ...
 
20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンス
20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンス20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンス
20190306 AWS Black Belt Online Seminar Amazon EC2 スポットインスタンス
 
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
Unleash the Power of Temporary AWS Credentials (a.k.a. IAM roles) (SEC390-R1)...
 
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기
 
Introducing AWS Firewall Manager - AWS Online Tech Talks
Introducing AWS Firewall Manager - AWS Online Tech TalksIntroducing AWS Firewall Manager - AWS Online Tech Talks
Introducing AWS Firewall Manager - AWS Online Tech Talks
 
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...
 
Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...
Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...
Hands-on SaaS: Constructing multi-tenant solutions with AWS - SVC307 - New Yo...
 
Black Belt Online Seminar AWS上の暗号化ソリューション
Black Belt Online Seminar AWS上の暗号化ソリューションBlack Belt Online Seminar AWS上の暗号化ソリューション
Black Belt Online Seminar AWS上の暗号化ソリューション
 
(STG401) Amazon S3 Deep Dive & Best Practices
(STG401) Amazon S3 Deep Dive & Best Practices(STG401) Amazon S3 Deep Dive & Best Practices
(STG401) Amazon S3 Deep Dive & Best Practices
 
AWS Security Week: AWS Secrets Manager
AWS Security Week: AWS Secrets ManagerAWS Security Week: AWS Secrets Manager
AWS Security Week: AWS Secrets Manager
 
AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기
AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기
AWS Summit Seoul 2023 | 바쁘다 바빠, 현대사회! Amazon Kendra로 원하는 자료를 적재적소에 찾아서 활용하기
 
AWS Route53
AWS Route53AWS Route53
AWS Route53
 
Become an AWS IAM Policy Ninja
Become an AWS IAM Policy NinjaBecome an AWS IAM Policy Ninja
Become an AWS IAM Policy Ninja
 
Identity and Access Management: The First Step in AWS Security
Identity and Access Management: The First Step in AWS SecurityIdentity and Access Management: The First Step in AWS Security
Identity and Access Management: The First Step in AWS Security
 
20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced Session
20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced Session20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced Session
20190213 AWS Black Belt Online Seminar Amazon SageMaker Advanced Session
 
(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIs
(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIs(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIs
(DEV203) Amazon API Gateway & AWS Lambda to Build Secure APIs
 
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
 
Construyendo aplicaciones Serverless
Construyendo aplicaciones ServerlessConstruyendo aplicaciones Serverless
Construyendo aplicaciones Serverless
 
Amazon ElastiCache and Redis
Amazon ElastiCache and RedisAmazon ElastiCache and Redis
Amazon ElastiCache and Redis
 

Similar to AWS Lambda RDS Best Practices

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 EventBoaz Ziniman
 
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...Chris Munns
 
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...Amazon Web Services
 
Serverless Architectural Patterns: Collision 2018
Serverless Architectural Patterns: Collision 2018Serverless Architectural Patterns: Collision 2018
Serverless Architectural Patterns: Collision 2018Amazon Web Services
 
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 2018Amazon Web Services
 
SRV315 Building Enterprise-Grade Serverless Apps
 SRV315 Building Enterprise-Grade Serverless Apps SRV315 Building Enterprise-Grade Serverless Apps
SRV315 Building Enterprise-Grade Serverless AppsAmazon Web Services
 
Serverless SaaS apllications on AWS
Serverless SaaS apllications on AWSServerless SaaS apllications on AWS
Serverless SaaS apllications on AWSAmazon Web Services
 
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...Amazon Web Services
 
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 ServerlessChris Munns
 
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 IsraelAmazon Web Services
 
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 serversAmazon Web Services
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural PatternsAmazon Web Services
 
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 ClubBoaz Ziniman
 
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 PracticesVladimir Simek
 
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 serversAmazon Web Services
 
Microservices & Data Design: Database Week SF
Microservices & Data Design: Database Week SFMicroservices & Data Design: Database Week SF
Microservices & Data Design: Database Week SFAmazon Web Services
 
Microservices and Data Design
Microservices and Data DesignMicroservices and Data Design
Microservices and Data DesignAWS Germany
 
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 FranciscoAmazon Web Services
 
Introduction to Serverless on AWS
Introduction to Serverless on AWSIntroduction to Serverless on AWS
Introduction to Serverless on AWSAmazon Web Services
 

Similar to AWS Lambda RDS Best Practices (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
 
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
 
Introduction to Serverless on AWS
Introduction to Serverless on AWSIntroduction to Serverless on AWS
Introduction to Serverless on AWS
 

More from Amazon Web Services

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...Amazon Web Services
 
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...Amazon Web Services
 
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 FargateAmazon Web Services
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSAmazon Web Services
 
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 Amazon Web Services
 
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...Amazon Web Services
 
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...Amazon Web Services
 
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 WorkloadsAmazon Web Services
 
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 sfatareAmazon Web Services
 
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 NodeJSAmazon Web Services
 
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 webAmazon Web Services
 
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 sfatareAmazon 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 AWSAmazon 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 DeckAmazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without serversAmazon 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
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceAmazon Web Services
 

More from 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
 

AWS Lambda RDS Best Practices

  • 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.