How do I connect to an Amazon Aurora DB cluster from outside a VPC?

Last updated: 2021-01-28

I have an Amazon Aurora DB cluster and I would like to connect to it from outside a VPC. I also want to secure my Aurora DB cluster from outside connections. How can I do this?

Short description

To connect to an Amazon Aurora DB cluster directly from outside the VPC, the instances in the cluster must meet the following requirements:

  • The DB instance must have a public IP address
  • The DB instance must be running in a publicly accessible subnet

As well as 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).

Resolution

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 these steps:

  1. 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. Choose Continue.
  6. Choose Modify DB Instance

Note: You don't need to choose Apply Immediately. For more information about how Apply Immediately can affect downtime, see Using the Apply Immediately parameter.

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, you can't 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. You can't connect to the DB instance from outside of the VPC if the underlying host is launched in a Private subnet.

Instead, create a DB subnet group with subnets of similar network configuration. For example, a DB subnet group for Public subnets, and a second DB subnet group for Private subnets. For more information, see Working with a DB instance in a subnet group.

Follow these steps to ensure that the subnet used by your DB instance has internet access:

  1. 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.

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"

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.


Did this article help?


Do you need billing or technical support?