Search code examples
aws-lambdaamazon-rdsmysql2node-mysql2

mysql2 TypeError: f.ClientHandshake is not a constructor


I'm trying to use mysql2 to connect to an RDS MySQL instance. When I use the package locally, everything works fine. However, when I use it inside an AWS Lambda function, I get this cryptic error:

TypeError: f.ClientHandshake is not a constructor
at new g (/var/task/index.js:275:62824)
at new o (/var/task/index.js:275:224046)
at e.exports.getConnection (/var/task/index.js:275:218705)
at e.exports.execute (/var/task/index.js:275:220197)
at /var/task/index.js:275:372341
at new Promise (<anonymous>)
at c.execute (/var/task/index.js:275:372308)
at /var/task/index.js:357:14189
at E (/var/task/index.js:316:24416)
at Generator._invoke (/var/task/index.js:316:24204)

Any idea what the issue is? I'm confident that the roles/security groups are all configured correctly.


Solution

  • Turns out disabling minification in Webpack fixed the issue.

    This can be done by updating the webpack.config.js to include

    optimization: {
        // We no not want to minimize our code.
        minimize: false
    },