How to connect Node Sequelize to Amazon RDS MySQL with Multi-AZ probably

15,073

Solution 1

Here is how i got connected with my RDS:

 var config = require(__dirname + '/../config/config.json')[env];
 // your config file will be in your directory
 var sequelize = new Sequelize(config.database, config.username, config.password, {
    host: '****.****.us-west-1.rds.amazonaws.com',
    port: 5432,
    logging: console.log,
    maxConcurrentQueries: 100,
    dialect: 'postgres',
    dialectOptions: {
        ssl:'Amazon RDS'
    },
    pool: { maxConnections: 5, maxIdleTime: 30},
    language: 'en'
})

Solution 2

The previous answer didn't work for me, after some research, this options object did:

var options = {
  host: settings.database.host,
  port: settings.database.port,
  logging: console.log,
  maxConcurrentQueries: 100,
  dialect: 'mysql',
  ssl: 'Amazon RDS',
  pool: { maxConnections: 5, maxIdleTime: 30 },
  language: 'en',
}

I'm running a RDS MySQL and a EC2 instance in the same default VPC, this options object worked when connecting a node app from that EC2 with the RDS using sequelize.

Share:
15,073
Manuel
Author by

Manuel

Hi there, I'm a Digital & Technology Evangelist! I helps customers to evolve ideas to business models and solutions and realizes them. My strength? I combine business knowledge, a growth & lean startup mindset, coaching and methodology like design thinking, business model canvas (bmc) value proposition design (vpd) with latest state of the art technologies. Technologie vise I focuse on cloud, aws serverless, progressive web applications (pwa) and augmented reality (ar/mr). Currently I'm working as a consultant at OPITZ CONSULTING. Having the OC|Lab in my background I can offer companies a lab and innovation space to realize and test new ideas!

Updated on June 07, 2022

Comments

  • Manuel
    Manuel almost 2 years

    I'm using an Amazon RDS hosted MySQL with Multi-AZ Support. Just could not find any information on how to connect Sequelize to Amazon RDS properly so that Sequelize is handling fail-overs etc. accordingly?

    I'm just using the following config, but do not know if this is enough or recommended?

    sequelizeConfig = {
      logging: false,
      pool: { maxConnections: 5, maxIdleTime: 30},
      sequelizeConfig[dialectOptions] = {
        ssl: 'Amazon RDS'
      }
    }
    

    Using Amazon RDS with Multi-AZ I consider the following is important:

    1. Try reconnecting if connection got lost, until it is available again
    2. Don't cache mysql server ip address too long (Amazon suggests less than 1 min)

    Amazon Docs are not writing anything about connection handling and pooling.

  • Manuel
    Manuel almost 6 years
    can you provide an additional example for iam authentication please?
  • Manuel
    Manuel almost 6 years
    Thx for the fast reply anyways!
  • Amiga500
    Amiga500 almost 6 years
    What do you put in the ssl? Just the string Amazon RDS??
  • Omar Faroque Anik
    Omar Faroque Anik almost 6 years
    Yes, I believe. I did it a year ago.
  • hitautodestruct
    hitautodestruct over 5 years
    Worked for me, Except I used dialect: 'mysql' instead of postgres
  • pgeimer
    pgeimer almost 5 years
    @Manuel You have to create an auth token which you pass as password: docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/RDS/Signer.h‌​tml
  • GaryMcM
    GaryMcM about 3 years
    FYI maxConcurrentQueries has not been used since 2014: github.com/sequelize/sequelize/issues/2405