sidorares / sidorares/node-mysql2
authSwitchHandler not being triggered
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
Hi,
I've been trying to set up IAM authentication for my AWS RDS instance and can't seem to get it working.
I believe I have everything correct on the infrastructure side but I keep getting a Access denied error.
In the authSwitchHandler function I've added a console.log but it never seems to get triggered.
Is there any reason why it wouldn't happen?
I've put some example code that I'm trying to execute below.
Thanks,
Gary
const AWS = require('aws-sdk');
const mysql = require('mysql2/promise');
const signer = new AWS.RDS.Signer({
region: process.env.REGION,
hostname: process.env.DB_HOSTNAME,
port: 3306,
username: process.env.DB_USERNAME,
});
const token = signer.getAuthToken();
exports.main = async (event, context, callback) => {
const config = {
host: process.env.DB_HOSTNAME,
user: process.env.DB_USERNAME,
password: token,
database: process.env.DB_NAME,
ssl: 'Amazon RDS',
authSwitchHandler: (data, cb) => {
console.log('authSwitchHandler', data);
cb(null, Buffer.from(`${token}\0`));
},
};
console.log('Config', config);
const connection = await mysql.createConnection(config);
console.log('Connection', connection);
return callback(null, {
statusCode: 200,
body: true,
});
};
{
"errorMessage": "Access denied for user 'user'@'x.x.x.x' (using password: YES)",
"errorType": "Error",
"stackTrace": [
"Object.createConnection (/var/task/node_modules/mysql2/promise.js:31:31)",
"exports.main (/var/task/src/handler.js:26:34)"
]
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The reproduction is in src/handler.js, with the failure reported at mysql.createConnection in the stack trace; start by tracing how the mysql2 connection processes authSwitchHandler for this AWS RDS example. A useful outcome is a confirmed explanation, reproduction, and documented expected behavior or correction, since the issue does not name a target file or test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript, mysql, node.js
- Domain
- authentication, backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100