Error connecting with AWS RDS instance using Sequelize in lambda function

99 Views Asked by At

I have started using Serverless Stack for the first time and this is my first experience with serverless applications. I am connecting my AWS RDS instance with sequelize in my lambda function and it is failing with error:

Error connecting database: SequelizeConnectionError: connect ETIMEDOUT 10.0.143.224:5432

This is my RDS resource definition code

const database: RDS = new RDS(stack, DatabaseConst.RDS_ID, {
    engine: "postgresql11.13",
    defaultDatabaseName: databaseName,
    cdk: {
        cluster: {
            credentials: Credentials.fromSecret(databaseSecret),
        },
    },
});

And this is my AWS Api Gateway resource definition which triggers the lambda function

const api: Api<AuthorizedApi> = new Api<AuthorizedApi>(stack, ApiConst.ApplicationApi, {
    //...
    defaults: {
        function: {
            //...
            bind: [database]
        },
    },
    routes: //...
});

In the lambda function, there is a normal Sequelize connection instance

const sequelize: Sequelize = new Sequelize({
    ...databaseConfig,
    dialect: "postgres",
    dialectModule: pg,
    logging: console.log,
    pool: {
        max: 2,
        min: 0,
        idle: 0,
        acquire: 3000,
    },
});

Any help would be appreciated. Thank you

0

There are 0 best solutions below