Lambda Function with Database

Hello everyone, In this blog we will talk about how to handle database operation in lambda function.

One of the problem that lambda function solves is that it abstract away the handling of server(CPU, Memory etc) and integration with many AWS Services.

This is very good but if your lambda function also handled database operation then managing these database connection in lambda becomes hard, as each time new lambda is invoked, you need to open one database connection.

Lambda Invokation with API gateway

In such cases, is lambda invocation count is very few then we should not have any problem, but if these lambda function are getting invoked many times, then we will run out of open database connection provided by RDS or in general any database. As there is limit on how many open database connection you could have and this also depends on database configuration(you may have pay more money just to have more database connection).

To deal this problem, you could create a proxy between your lambda and database. In this architecture, Lambda connects to database through Proxy and this database proxy manages database connection.

Lambda Invocation with API gateway(Using RDS Proxy)

In this architecture, RDS Proxy manages connection with database and caches this connection for reusing.

Thanks for reading….

Leave a Reply