I use API Gateway + Lambda + DB.
If many requests make, Too many connections Error occurs.
For testing, I don't want to increase max connections option.
Is it possible to use SQS -> Lambda -> API Gateway -> Lambda -> DB?
Or other way?
I use API Gateway + Lambda + DB.
If many requests make, Too many connections Error occurs.
For testing, I don't want to increase max connections option.
Is it possible to use SQS -> Lambda -> API Gateway -> Lambda -> DB?
Or other way?
First, make sure not to create a new connection in each invocation of your lambda. You should create the connection outside of the lambda handler (so it will be made at initialization time), or use connection pooling.
By doing that, the number of connections to the DB will be as about the number of concurrent invocations.
You can set the concurrency limit of the lambda to have a limit on the active connections (but it means that triggering your lambda may fail due to concurrency limit when you reach it).
You can trigger your lambda with SQS, and by that, the requests will be queued in case of reaching the concurrency limit, until previous requests are ended.
Using SQS without setting a concurrency limit for your lambda won't solve the problem, because the number of concurrent invocations (=active connections) can still get high.
I don't see any benefit by doing something like 'SQS -> Lambda -> API Gateway -> Lambda -> DB'. A possible use case will be 'API Gateway -> SQS -> Lambda'.
You can also just use 'API Gateway -> Lambda' with setting the lambda concurrency limit. In that case some calls to the API Gateway may fail, and should be retried with exponential backoff.