Wondering how to connect to an Amazon Aurora DB cluster from outside a VPC? We can help you.
Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.
Today, let us see how our Support Techs perform this task.
How to connect to an Amazon Aurora DB cluster from outside a VPC?
In order to connect to an Amazon Aurora DB cluster directly from outside the VPC, the instances in the cluster must meet the below requirements:
- The DB instance must have a public IP address
- The DB instance must be running in a publicly accessible subnet
Also, configuring your DB instance so that it can be connected to from outside a VPC, you can also secure the connections using Transport Layer Security (TLS), formerly known as Secure Sockets Layer (SSL).
Today, let us see the steps followed by our Support techs to perform this task.
Set Publicly Accessible setting of DB instance to Yes
The Publicly Accessible setting for an Amazon Relational Database Service (Amazon RDS) DB instance controls the assignment of a Public IP address to the DB instance.
If this is set to No, the DB instance does not have a Public IP address.
If this is set to Yes, the DB instance has both Public and Private IP addresses.
To change the Publicly Accessible setting of the DB instance to Yes, follow below steps:
1.Firstly, open the Amazon RDS console.
2.Choose Databases from the navigation pane, and then choose the DB instance.
3.Choose Modify.
4.Under Connectivity, extend the Additional configuration section, and then choose Publicly accessible.
5.Then, choose Continue.
6.Finally, choose Modify DB Instance
Run DB instance in a public subnet
A public subnet is a subnet that is associated with a route table which has a route to internet gateway, typically the default route, 0.0.0.0/0.
This route enables the DB instances in a subnet to communicate with resources outside the VPC.
For Amazon Aurora DB instances, it is not possible choose a specific subnet.
Instead, choose a DB subnet group when you create the instance.
A DB subnet group is a collection of subnets that belong to a VPC.
When it creates the underlying host, Amazon RDS randomly chooses a subnet from the DB subnet group.
Typically, a VPC has both public and private subnets.
If the DB subnet group also contains both public and private subnets, then you can launch the underlying host in either a Public subnet or Private subnet.
It is not possible to connect to the DB instance from outside of the VPC if the underlying host is launch in a Private subnet.
Instead, create a DB subnet group with subnets of similar network configuration.
Follow these steps to ensure that the subnet used by your DB instance has internet access:
1.Firstly, verify that your VPC has an internet gateway attached to it.
2.Verify that all the subnets in the DB subnet group use a route table with Internet Gateway.
- If the subnet uses the main route table of the VPC, then add the route for Internet Gateway (Destination is 0.0.0.0/0).
- If required, create a custom route table with route to Internet Gateway and associate it to the subnet.
3.Add the source Public IP address that you want to connect to the DB instance from in the inbound rules for the security group.
4.For rule Type, choose MySQL/Aurora or PostgreSQL, depending on your engine type.
5.For Source, enter the CIDR range manually, or choose My IP to connect to the DB instance from the same workstation.
Secure the DB cluster from connections from outside the VPC
You can use TLS to encrypt connections that come from outside a VPC because the data transfer happens over the internet.
To make sure that you’re using the highest level of security, use the ssl-ca parameter to pass the CA certificate, and then enable hostname validation.
Use the following example commands for TLS connections, depending on the version of Aurora you are using.
Firstly, Aurora MySQL 5.6 and later:
mysql -h test-aurora-56.cluster-xxxxxxxxxxxx.us-east-1.rds.amazonaws.com -u master_user --ssl-ca=rds-combined-ca-bundle.pem --ssl-verify-server-cert
Aurora MySQL 5.7 and later:
mysql -h test-aurora-57.cluster-xxxxxxxxxxxx.us-east-1.rds.amazonaws.com -u master_user --ssl-ca=rds-combined-ca-bundle.pem --ssl-mode=VERIFY_IDENTITY
Aurora PostgreSQL:
psql -h test-aurora-pg.cluster-xxxxxxxxxxxx.us-east-1.rds.amazonaws.com -p 5432 "dbname=postgres user=master_user sslrootcert=rds-combined-ca-bundle.pem sslmode=verify-full"
Please note you can also enforce TLS for DB clusters.
For Aurora MySQL, you must enforce TLS at the database user level. For Aurora PostgreSQL, set the parameter rds.force_ssl to 1.
[Need help with the process? We’d be happy to assist]
Conclusion
In short, we saw how our Support Techs connect to an Amazon Aurora DB cluster from outside a VPC.
0 Comments