

# Connecting to the routing endpoint

When you enable routing for a database cluster group for Aurora, applications can connect to one address, the **routing endpoint**. The routing layer behind it sends each routed statement to the member cluster that holds its data. Every member cluster also keeps its own cluster and instance endpoints, so you choose how each application connects. Enabling routing doesn't require any application to use it. A group without routing has no routing endpoint, and you connect to its member clusters as you connect to any Aurora DB cluster. For more information, see [Connecting to an Amazon Aurora DB cluster](Aurora.Connecting.md).

**Topics**
+ [Finding the routing endpoint name](#databaseclustergroups-routing-endpoint-names)
+ [Connecting with a client](#databaseclustergroups-connecting-to-the-routing-endpoint)
+ [Choosing where to connect](#databaseclustergroups-choosing-a-way-to-connect)
+ [Connecting to a member cluster directly](#databaseclustergroups-connecting-direct)
+ [Managing connections](databaseclustergroups-connection-management.md)
+ [Running queries and transactions through the routing layer](databaseclustergroups-queries.md)

## Finding the routing endpoint name
<a name="databaseclustergroups-routing-endpoint-names"></a>

The service generates the routing endpoint name from the group identifier and the DNS identifier of your account. Read the name from the API, and don't build it yourself. The routing endpoint is reachable from your Amazon VPC and from networks connected to it, and it isn't publicly accessible. For more information, see [Connectivity within a VPC](databaseclustergroups-network.md#databaseclustergroups-network-vpc-connectivity).

**To find the routing endpoint name**
+ With the console, read the routing endpoint on the group's **Connectivity** tab. With the AWS CLI or the Amazon RDS API, describe the group, and read `Endpoint` and `Port` from `RoutingEndpointConfigurationInfo`. The steps are in the following tabs.

------
#### [ Console ]

**To find the routing endpoint (console)**

1. Sign in to the AWS Management Console and open the Amazon RDS console at [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/).

1. In the navigation pane, choose **Database cluster groups**, and then choose the group.

1. Choose the **Connectivity** tab.

1. Under **Router details**, copy the **Writer endpoint**, which is the routing endpoint.  
![Router details section with the Writer endpoint, the Reader endpoint, and the Router admin username of a group.](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/dbcg-console-routing-endpoint.png)  
   The Router details section of the Connectivity tab.

------
#### [ AWS CLI ]

```bash
aws rds describe-db-cluster-groups --region {{REGION}} --db-cluster-group-identifier {{GROUP_IDENTIFIER}} \
  --query 'DBClusterGroups[0].RoutingEndpointConfigurationInfo.[Endpoint,Port]' --output text
```

------
#### [ Amazon RDS API ]

Call `DescribeDBClusterGroups` with `DBClusterGroupIdentifier`, and read `Endpoint` and `Port` from `RoutingEndpointConfigurationInfo` in the response.

------

Consider the following points:
+ To scope an egress allowlist, use the routing endpoint's Amazon VPC, subnets, and security groups, as [Finding the routing endpoint's Amazon VPC endpoints](databaseclustergroups-network.md#databaseclustergroups-network-vpc-endpoints) describes.
+ The routing endpoint uses an AWS managed certificate, a public certificate from AWS Certificate Manager that chains to the Amazon Trust Services root certificates. Most standard trust stores already have these root certificates. For TLS settings, see [Encryption in transit (TLS) and at rest](databaseclustergroups-tls.md).

## Connecting with a client
<a name="databaseclustergroups-connecting-to-the-routing-endpoint"></a>

Connect to the routing endpoint as a router user, from a host that can reach the endpoint, with your engine's standard client or driver. For router users, see [Router users and routing layer privileges](databaseclustergroups-router-users.md). The routing layer authenticates you when the connection opens, and the member cluster that holds the data authorizes each statement. A credential that connects can therefore be refused on its first statement, so handle a permission failure where you handle statement errors. Router users sign in with a password. IAM database authentication isn't available at the routing endpoint, as described in [IAM database authentication](databaseclustergroups-iam.md#databaseclustergroups-iam-db-auth).

**Before you begin**

Complete the following tasks before you connect through the routing endpoint:
+ With the console or the AWS CLI, enable routing on the group, which creates the routing endpoint. For more information, see [Enabling or disabling routing](databaseclustergroups-group-lifecycle.md#databaseclustergroups-turning-routing-on-or-off).
+ At the routing endpoint, create a router user for each database user that your application connects with. On each member cluster that the user must reach, create a member cluster user with the same name and grant it the privileges that your application needs there. For more information, see [Router users and member cluster users](databaseclustergroups-router-users.md#databaseclustergroups-managing-router-users-and-member-cluster-users).
+ In the security groups of the routing endpoint, allow inbound traffic from your application on the routing endpoint's port. These security groups control traffic from your applications to the routing endpoint, not traffic between the routing layer and the member clusters. For more information, see [Security group rules](databaseclustergroups-network.md#databaseclustergroups-network-security-groups).

The routing endpoint requires TLS 1.2 or 1.3. It refuses a client connection without TLS, with error `3159` on Aurora MySQL after the credential and account-lock checks. The routing layer connects to the member clusters with mutual TLS. Both connections use AWS managed certificates. Require TLS in every client and driver that connects to the routing endpoint. To check the TLS version and cipher, read them from your client or driver, because the routing endpoint doesn't return the server's TLS status. For client TLS settings, see [Encryption in transit (TLS) and at rest](databaseclustergroups-tls.md).

**To connect to the routing endpoint**

1. With the AWS CLI, read the routing endpoint name and port, as described in [Finding the routing endpoint name](#databaseclustergroups-routing-endpoint-names).

1. From your client host, connect to the routing endpoint as a router user, with TLS required. This opens a routed session. The command follows this procedure.

1. At the routing endpoint, list the member clusters in the group. The routing layer answers this read itself, with each member cluster alias.

   ```sql
   SELECT * FROM dbclustergroup_sys.member_cluster_mappings;
   ```

1. At the routing endpoint, read one row from a mapped table to confirm that a statement routes. A table-less `SELECT 1` doesn't prove routing, because the routing layer answers it itself.

To connect from your browser, choose **Launch CloudShell** on the group's **Connectivity** tab. Before CloudShell can connect, the routing endpoint must be available and the group must have an admin username.

For step 2, connect with TLS required and a utf8mb4 handshake. The option file holds the user name and password of the router user. To name a router database name as the initial database, add `-A` and `-D {{ROUTER_DB}}`, so that the client starts without reading table names.

```bash
mysql --defaults-extra-file={{OPTION_FILE}} -h {{ROUTING_ENDPOINT}} -P {{PORT}} \
  --ssl-mode=REQUIRED --default-character-set=utf8mb4
```

For step 4, read one row from a mapped table.

```sql
SELECT * FROM {{ROUTER_DB}}.{{ROUTER_TABLE}} LIMIT 1;
```

The routing endpoint accepts only a utf8mb4 handshake. It refuses any other client character set with error `1115`. A `mysql` client without a UTF-8 locale sends `latin1`. Many container images and scheduled jobs have no UTF-8 locale. Start every client with `--default-character-set=utf8mb4`, or set `default-character-set=utf8mb4` under `[client]` in its option file. A client that doesn't support TLS can't connect. For the supported collations, see [Character sets and collations](databaseclustergroups-character-sets.md).

The routing layer refuses a connection whose user name has no matching router user.

The initial database and a later `USE` set the same session context. The routing layer holds the router database name that a `USE` names and resolves it on the next statement that needs it. A misspelled or unmapped router database name returns its error on that statement, not on the `USE`, so don't read a successful `USE` as proof that the database exists.

`SELECT DATABASE()` returns the router database name when it's a top-level expression. Inside an object that the member cluster evaluates, such as a view or a stored procedure, it returns the cluster database name.

In an application, set the same options in the connection string or driver settings: TLS required and a utf8mb4 character set. The settings that are specific to the group are the following:
+ Text and binary-protocol prepared statements work on a scaleout table. The routing layer routes each execute by the routing key value bound for that execute. You don't need to turn off server-side prepared statements. In a session without a pin, the routing layer refuses server-side cursors, long data, and a reset (`COM_STMT_RESET`) of a statement that it forwarded to a member cluster. For more information, see [Statement compatibility](databaseclustergroups-compatibility.md).
+ For a session that writes data mappings, turn on autocommit. The routing layer rejects a mapping write inside an open transaction, and a session with `autocommit=0` counts as an open transaction.

For driver versions and settings, see [Drivers, ORMs, and tools](databaseclustergroups-drivers-orms.md).

If the sign-in fails, see [Troubleshooting connection and sign-in problems](databaseclustergroups-ts-connections.md). For pool, driver, and timeout settings, see [Managing connections](databaseclustergroups-connection-management.md).

## Choosing where to connect
<a name="databaseclustergroups-choosing-a-way-to-connect"></a>

You can reach the data in a group through the routing endpoint, through a pinned session on the routing endpoint, or directly on a member cluster, as the following table shows. You can use all of them at the same time. For how routed sessions, session pins, and direct connections behave, see [Sessions, transactions, and session pinning](databaseclustergroups-sessions.md).


| Way to connect | Use it for | Names you use | 
| --- | --- | --- | 
| Routing endpoint (routed session) | Application reads and writes on data that the data mappings place. Data mapping and scaleout table changes, in a session that isn't pinned. | Router names from the data mappings | 
| Pinned session on the routing endpoint | Work on one member cluster without a new connection. A pinned session passes its statements through, so anything that the member cluster accepts runs there, such as DDL rollouts, administrative statements, and catalog reads. | Cluster names on that member cluster | 
| Direct connection to a member cluster's own endpoint | Any application that you keep on its member cluster, and a group without routing. Also use it for long maintenance jobs, schema change tools, bulk loads into a database that one member cluster owns, reads from a member cluster's Aurora Replicas, and monitoring agents that read server status. | Cluster names on that member cluster | 

You can combine these ways: some applications on the routing endpoint, others on member cluster endpoints. When data mappings spread an application's data across member clusters, send its writes through the routing endpoint, so that each write reaches the member cluster that the mappings name. Keep session pins out of pooled application connections, as [Connection pools and session pins](databaseclustergroups-connection-management.md#databaseclustergroups-bp-pools-and-session-pins) describes. For both DDL paths, see [Rolling out schema changes](databaseclustergroups-schema-changes.md).

The group has one routing endpoint, for read-write traffic. A routed statement runs on the writer of the member cluster that holds its rows, so it sees every write committed there. To read from replicas, connect directly to a member cluster's reader endpoint or instance endpoints.

**Note**  
At preview, a reader endpoint isn't available for a database cluster group for Aurora. The `ReaderEndpoint` value that the API returns for a database cluster group reaches the writers of the member clusters and accepts writes, so don't rely on it to keep writes out. To send read-only traffic to Aurora Replicas, connect directly to the reader endpoint or instance endpoints of each member cluster.

## Connecting to a member cluster directly
<a name="databaseclustergroups-connecting-direct"></a>

Every member cluster stays reachable on its own cluster and instance endpoints for as long as it's in the group, whether or not routing is enabled. On a direct connection, you use the member cluster's cluster names, and the member cluster runs your statements as a standalone Aurora DB cluster does. You connect, use TLS, and read from Aurora Replicas as on any Aurora DB cluster, and TLS follows the member cluster's own settings. For the endpoint types, see [Amazon Aurora endpoint connections](Aurora.Overview.Endpoints.md). For connecting, see [Connecting to an Amazon Aurora DB cluster](Aurora.Connecting.md). For TLS, see [TLS connections to Aurora MySQL DB clusters](AuroraMySQL.Security.md#AuroraMySQL.Security.SSL).

Point monitoring agents at each member cluster's endpoints. Through the routing endpoint, `SHOW STATUS` and `SHOW GLOBAL STATUS` on Aurora MySQL return no status counters of the member clusters. For how to monitor member clusters, see [Monitoring database cluster groups for Aurora](databaseclustergroups-monitoring.md).