Connecting to Aurora MySQL Serverless with Node

假装没事ソ 提交于 2021-02-10 15:53:19

问题


I'm trying to connect to my Aurora Serverless MySQL DB cluster using the mysql module, but my connection always times out.

const mysql = require('mysql');

//create connection
const db = mysql.createConnection({

    host     : 'database endpoint',
    user     : 'root',
    password : 'pass',
    database : 'testdb'

});


//connect
db.connect((err) => {
    if(err){
        throw err;
        console.log('connection failed');
    }
    console.log('mysql connected...');
})
db.end();

My cluster doesn't have a public IP address so I'm trying to use the endpoint. I've successfully connected to the db using Cloud9, but I can't connect using node. I must be missing something.


回答1:


Aurora Serverless uses an internal AWS networking setup that currently only supports connections from inside a VPC, and it must be the same VPC where the serverless cluster is deployed.

Q: How do I connect to an Aurora Serverless DB cluster?

You access an Aurora Serverless DB cluster from within a client application runing in the same Amazon Virtual Private Cloud (VPC). You can't give an Aurora Serverless DB cluster a public IP address.

https://aws.amazon.com/rds/aurora/faqs/#serverless

This same limitation applies to Amazon EFS, for architecturally similar reasons. You can work around the limitation in EFS, and the same workaround could be used for Aurora Serverless, but you'd need to disable the health checks entirely since those health checking connections would keep the instance alive all the time. Exposing a database to the Internet is a practice best avoided.

You could also use some VPN solutions. They would need to be instance-based and would probably need to use NAT to masquerade the client address behind the VPN instance's internal address -- that's effectively what the proxy workaround mentioned above does, but at a different OSI layer.



来源:https://stackoverflow.com/questions/52824948/connecting-to-aurora-mysql-serverless-with-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!