问题
I was trying to use AWS Aurora Serverless for MySQL in my project, but I am impossible to connect to it, though I have the endpoint, username, password.
What I have done:
- From AWS console managment, I select RDS > Instances > Aurora > Serverless
- Leave the default settings
- Create database
- AWS will only create an AWS Cluster
- I open MySQL Workbench, and use endpoint, username, password to connect the database
Ressult:
Your connection attempt failed for user 'admin' from your host to server at xxxxx.cluster-abcdefg1234.eu-west-1.rds.amazonaws.com:3306: Can't connect to MySQL server on 'xxxxx.cluster-abcdefg1234.eu-west-1.rds.amazonaws.com' (60)
Did I make any wrong steps ? Please advice me.
****EDIT****
I tried to create another Aurora database with capacity type: Provisioned. I can connect to the endpoint seamlessly with username and password by MySql workbench. It means that the port 3306 is opened for workbench.
About the security group:
回答1:
From https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/aurora-serverless.html :
- You can't give an Aurora Serverless DB cluster a public IP address.
- You can access an Aurora Serverless DB cluster only from within a virtual private cloud (VPC) based on the Amazon VPC service.
- You can't access an Aurora Serverless DB cluster's endpoint through an AWS VPN connection or an inter-region VPC peering connection. There are limitations in accessing a cluster's endpoint through an intra-region VPC peering connection; for more information, see Interface VPC Endpoints (AWS PrivateLink) in the Amazon VPC User Guide. However, you can access an Aurora Serverless cluster's endpoint through an AWS Direct Connect connection.
So, aside from SSH-ing through an EC2 instance, you can also access your serverless cluster with mySQL Workbench with AWS Direct Connect.
回答2:
One way to connect to an Aurora Serverless DB cluster is by using an Amazon EC2 instance. You cannot create publicly accessible Aurora Serverless DB clusters in the Preview. This task walks you through creating a publicly accessible Amazon EC2 instance in your VPC. You can use this Amazon EC2 instance to connect to an Aurora Serverless DB cluster.
This is directly from the docs provided upon preview signup. Please try creating an EC2 instance and using SSH Tunnel method in your MYSQL Workbench or SQL UI of choice. During the preview the Aurora Serverless is not allowed to be set to publicly accessible.
回答3:
Initially, I was got stuck in the same scenario Points to be noted while connecting AWS RDS Aurora
Cant connect Public, you need an EC2 instance with the same region where Aurora is been created.
Aurora Public access should be checked No(it worked for me).
You need to create the security group, where you should add Inbound and Outbound rules(IpAddress of EC2 instances).
Ex: Type = MYSQL/AURORA, Protocol=TCP, PortRange=3306,Source=Custom and your IP Address Range,
modify instance and security group to the instance and apply the changes immediately.
While creating Aurora, u will create MasterName, Pwd, and default schema to connect.
After creating, go to cluster and take the cluster endpoint and log in with your EC2 Instance and with MySQL Workbench, Hostname as your cluster endpoint, username and pwd entered while creating aurora database.
回答4:
A common pattern used by customers for connecting to VPC only services (like Aurora Serverless, Amazon Neptune, Amazon DocDB etc) is to have a middle layer (EC2 instance, or ALB etc) and making the middle layer accessible from outside the VPC. If your use case is just trying out some queries or connecting a workbench, then the easiest thing to do is:
- Resolve the DNS of the serverless db and obtain its IP
- Create an ALB in your VPC, with a target group to the IP that you found in #1
- Create a new security group and attach that to your ALB
- Update the SG to allow inbound from where ever you want. If you want public internet access, then allow inbound from all IPs, enable an internet gateway in your VPC, and use a public subnet for your ALB.
Once all of this is done, you would end up with a new DNS - that points to your ALB. Make sure that your ALB is set up correctly by:
- Using telnet to connect to your ALB endpoint.
telnet alb-endpoint alb-port
. If it succeeds, then you have a full end to end connection (not jsut to your ALB, but all the way through). - Verify ALB metrics to make sure that all health checks are passing.
Once this is done, use the ALB endpoint in workbench, and you are good to go.
This pattern is recommended only for non production systems. The concerning step is the one where you resolve the DNS to an IP - that IP is ephemeral, it can change when scale compute or failover happens in the background.
Hope this helps, let me know if you need more details on any step. Here is a related answer for Neptune:
Connect to Neptune on AWS from local machine
回答5:
My guess is your security group is not correctly setup for access. You need to explicitly allow remote access on that port to that instance.
From the official docs:
Two common causes of connection failures to a new DB instance are:
The DB instance was created using a security group that does not authorize connections from the device or Amazon EC2 instance where the MySQL application or utility is running. If the DB instance was created in a VPC, it must have a VPC security group that authorizes the connections. If the DB instance was created outside of a VPC, it must have a DB security group that authorizes the connections.
The DB instance was created using the default port of 3306, and your company has firewall rules blocking connections to that port from devices in your company network. To fix this failure, recreate the instance with a different port.
See here for more information:
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html
来源:https://stackoverflow.com/questions/51716530/aws-aurora-mysql-serverless-how-to-connect-from-mysql-workbench