We are using Sequelize within Aws Lambda and for the most part everything is working great however randomly it is erroring out with the following error:
ETIMEDOUT {"name":"SequelizeConnectionError","parent":{"errorno":"ETIMEDOUT","code":"ETIMEDOUT","syscall":"connect","fatal":true},"original":{"errorno":"ETIMEDOUT","code":"ETIMEDOUT","syscall":"connect","fatal":true}}
We are using Rds - mysql 8.0.15, Serverless framework, serverless-http, serverless-webpack. Here is our file configuration.
//db.js
... import all models
const sequelize = new Sequelize(
process.env.DATABASE,
process.env.DB_USER,
process.env.DB_PASSWORD,
{
host: process.env.DB_HOST,
port: process.env.STAGE === "dev" ? 3306 : 31304,
dialect: "mysql",
dialectOptions: { decimalNumbers: true },
pool: {
max: 10,
min: 0
}
}
);
const models = {};
// Initialize models
modules.forEach(module => ...
export default models;
//handler.js
import express from "express";
import serverless from "serverless-http";
import db from "./db";
const app = express();
app.use(async (req, res, next) => {
try {
const email = "get email from jwt ...";
req.user = await db.user.findOne({
where: { email }
});
return next();
} catch (e) {
logger.warn("An error occurred" , e);
res.status(500).send({ message: e.message });
}
});
app.use("/api", api);
app.get("*", (req, res) =>
res.status(404).json({ errorCode: 0, message: "Unrecognized route" })
);
const handler = serverless(app);
module.exports.handler = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
return handler(event, context);
};
I thought potentially that we reached the max mysql connections (which for my instance is 66) however the rds dashboard shows the most we have is in the 40's.
What are we doing wrong?