Sequelize with AWS RDS Proxy Connection Issues

1.3k views Asked by At

I've setup a Serverless API via AWS API Gateway and AWS Lambda thet leverages AWS RDS Proxy to connect to a RDS MySQL Database.

I'm opening the connection on every Lambda Execution by performing these operations:

sequelize = new Sequelize(process.env.DB, process.env.USER, process.env.PASS, {
            host: process.env.RDS_PROXY_ENDPOINT,
            dialect: 'mysql',
            dialectModule: mysql2
        });
...

 console.info("doing authenticate");
            await this.sequelize.authenticate();
 console.info("done, returning connection.");

... 

BUSINESS LOGIC (mostly CRUD operations)

...

finally{
  await sequelize.close();
}

Now, we are experiencing a random lambda timeout on some api calls, if we refresh the page the subsequent api call on the very same endpoint succeeds.

Question is:

Should I call sequelize close after having used the connection in my lambda function to release it to the proxy or not?

Here is my RDS Proxy Panel as you can see client connections are mostly 1 or 2 but I'm experiencing connection problems.

Any suggestion?

This is my RDS Proxy Panel

0

There are 0 answers