Saturday 27 May 2017

Knex js using incorrect database within AWS Elastic Beanstalk

I have uploaded a node app to aws elastic beanstalk and it has worked perfectly, apart from it using the wrong Knex database.

My knex file looks like this

module.exports = {
    production: {
        client: 'mysql',
        connection: {
            host: process.env.RDS_HOSTNAME,
            port: process.env.RDS_PORT,
            user: process.env.RDS_USERNAME,
            password: process.env.RDS_PASSWORD,
            database: process.env.RDS_DB_NAME,
        },
        pool: {
            min: 2,
            max: 10
        },
        migrations: {
            tableName: 'knex_migrations'
        }
    },
    development: {
        client: 'mysql',
        connection: {
            socketPath : '/Applications/MAMP/tmp/mysql/mysql.sock',
            user : 'root',
            password : 'root',
            database : 'testDb'
        },
        pool: {
            min: 2,
            max: 10
        },
        migrations: {
            tableName: 'knex_migrations'
        }
    }
};

I have set my NODE_ENV value to 'production' using the EB console, and returning 'process.env.NODE_ENV' confirms it to be 'production'.

However when I run a DB query, it errors with

error": {
    "code": "ENOENT",
    "errno": "ENOENT",
    "syscall": "connect",
    "address": "/Applications/MAMP/tmp/mysql/mysql.sock",
    "fatal": true
  }

Which shows it using the development database. I have returned all the variables for the RDS database and they are set by EB correctly. My 'npm start' is simply 'node dist/index.js'

Any ideas why its picking up the wrong database? If I hard code both of them to the production config, it uses it.



via drm18272

No comments:

Post a Comment