The recommended connection_limit for Prisma Client in AWS Lambda serverless functions is 1.
This recommendation exists because:
Connection multiplication: Each Lambda instance creates its own PrismaClient with its own connection pool. During traffic spikes, AWS Lambda spawns multiple instances, rapidly multiplying total database connections.
Idle connections: Paused Lambda functions keep connections open, blocking them from other instances.
Preventing exhaustion: Multiple concurrent functions with higher connection limits can quickly exhaust your database's maximum connection limit.
Configuration example:
// In your schema.prisma or connection URL
datasource db {
provider = "postgresql"
url = "postgresql://user:password@host:5432/database?connection_limit=1"
}
Additional strategies:
- Set your AWS Lambda concurrency limit below your database's max connections
- Consider using an external connection pooler like PgBouncer or Prisma Accelerate
- Start with
connection_limit=1and optimize based on your specific needs
Sources: