jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
443 stars 63 forks source link

Timeout issue for Aurora Postgresql Serverless #40

Closed phongthienvu closed 4 years ago

phongthienvu commented 4 years ago

Hi, This client is very useful for using Data API with Aurora Serverless, however, it 's working only in local (serverless offline). After deploying, it returned Timeout issue. I raised the issue in Stackoverflow. Please refer to the post

Any suggestion is appriciated.

DanielOrtel commented 4 years ago

I'm using Postgres Aurora as well and this package works, albeit it's missing support for a lot of postgres specific things.

After looking at your stackoverflow post, I'm wondering, did you enable the data API for your database? Here's their docs for being able to query the database as http

MarkMarsh commented 4 years ago

I'm using Postgres Aurora - I get a timeout if the database has to be started (I have pause after 5 minutes of inactivity set) but no problems once the database is running.

jeremydaly commented 4 years ago

@phongthienvu, this must be a permissions problem. Make sure that the IAM role being used by your Lambda function has access to Secrets Manager to access the database credentials.

rraziel commented 4 years ago

This issue should probably be reopened, as the problem does not have anything to do with access rights.

Basically, Aurora serverless has an auto-pause feature where it shuts down after idling for N minutes, and it takes anywhere from 30 seconds to 5 minutes to restart when it has been paused.

This means that the first time you do a query after it's been paused, it'll timeout. Now I assume for most requests that shouldn't be an issue (because it's probably better to catch the error and just show a message to the user such as "server unavailable, come back in 5 minutes" rather than having the lambda wait forever) but there are some use cases where you really want to wait, e.g. batches/jobs or - in our case - running schema changes when deploying.

I'm pretty sure all that's missing is documenting how to pass a connection/query timeout parameter to the data API client.