3 ms·
This article was missing a couple of major points: 1. He doesn't say whether the RDS DB is Postgres or MySQL. The MySQL connection times tend to be much shorte
by hn_throwaway_99 8y ago
This article was missing a couple of major points:
1. He doesn't say whether the RDS DB is Postgres or MySQL. The MySQL connection times tend to be much shorter than Postgres. With Postgres, it's a very good idea to put use a pgbouncer instance to implement connection pooling and have the Lambdas connect to that.
2. As others point out here, in AWS it is a very bad idea to have your RDS DB not behind a VPC. When you do that, it basically makes cold start times completely untenable for a user-facing synchronous function. Amazon has promised they are improving this situation, not sure what the status of this is.
3. Author points out some of this in his article, but caching your connection in global scope opens up a whole host of very difficult to track down bugs (e.g. you can have lots of cached connections open and thus killing your DB connection limits, needing to handle dead connections, etc.)
In my opinion, and with a lot of experience on a high traffic consumer site, it's a bad idea to cache connections in global scope. Either use MySQL or pgbouncer and connect in the function body.