Vla*_*gas 4 mysql amazon-web-services amazon-rds node.js node-mysql2
当我尝试连接到 mysql rds 代理时,出现连接超时。我遵循了这个教程
这是我的代码
import mysql2 from 'mysql2';
import AWS from 'aws-sdk';
const getConnection = async () => {
const signer = new AWS.RDS.Signer({
username: 'my-user-name',
hostname: 'proxy-name.proxy-someid.us-east-1.rds.amazonaws.com',
port: 3306
});
console.info('Connecting to MySQL proxy via IAM authentication');
const rdsSignerAuth = () => () => {
console.info('CALL rdsSignerAuth');
return signer.getAuthToken({
username: 'my-user-name',
region: 'us-east-1',
hostname: 'proxy-name.proxy-someid.us-east-1.rds.amazonaws.com',
port: 3306
});
};
let connection;
try {
connection = await mysql2.createConnection({
host: 'proxy-name.proxy-someid.us-east-1.rds.amazonaws.com',
user: 'my-user-name',
database: 'database-name',
connectTimeout: 60000,
ssl: { rejectUnauthorized: false },
authPlugins: { mysql_clear_password: rdsSignerAuth },
});
console.info('Connected');
}
catch (e) {
console.error(`MySQL connection error: ${e}`);
throw e;
}
return connection;
};
const mysql2Impl = async () => {
const connection = await getConnection();
//console.info({ type: 'connection', connection });
const result = await connection.promise().query('select * from destiny;');
console.info({ type: 'result', result });
};
export async function testRdsProxy(event, context){
console.info(JSON.stringify({ event, context }));
await mysql2Impl();
return 200;
}
Run Code Online (Sandbox Code Playgroud)
这就是回应
Error {
code: 'ETIMEDOUT',
errno: undefined,
message: 'connect ETIMEDOUT',
sqlState: undefined,
}
Run Code Online (Sandbox Code Playgroud)
我已经检查过我的 lambda 函数对“*”资源有一个策略“rds-db:connect”。此外,我检查了我的代理是否与我的 rds 数据库位于同一 VPC 和子网中。保存 RDS 凭据的秘密没问题。我做错了什么?
小智 10
该文档指出,RDS 代理无法公开访问,因此您的 lambda 函数需要与 rds 代理位于同一安全组中。请注意,当您将 lambda 设为 vpc 时,您的 lambda 可能会失去访问互联网的能力。谢谢。
| 归档时间: |
|
| 查看次数: |
5946 次 |
| 最近记录: |