18.3 Aurora Cluster Endpoints: Writer, Reader, and Custom Endpoints
Right, let’s talk endpoints. You’ve built your Aurora cluster, a beautiful symphony of compute and storage, but how do you actually talk to it? You don’t just shout into the void and hope the right database instance hears you. This is where endpoints come in—they’re the designated phone numbers for your cluster, and using the right one is the difference between a smooth operation and a catastrophic “why did I just delete the production table?!” moment.
Aurora, in its wisdom (and occasional madness), gives you a few types of these endpoints. You need to know what each one does, because getting it wrong is like asking for the vegetarian menu at a steakhouse—you might get fed, but it’s not going to be the experience you were hoping for.
The Writer Endpoint: There Can Be Only One
This is your golden ticket, the VIP pass, the one ring to rule them all. The writer endpoint (my-cluster.cluster-xyz.us-east-1.rds.amazonaws.com) always, always points to the one and only DB instance in your cluster that can handle write operations. This is non-negotiable. Aurora uses a single-writer model, so there’s only one primary instance at any given time.
You use this for all your INSERT, UPDATE, DELETE, DROP, ALTER—you get the idea. Anything that changes state. The brilliant part? This endpoint automatically fails over. If the current primary instance decides to take an unscheduled nap (failure), Aurora will promote a replica to primary, and this very same DNS name will seamlessly start pointing to the new boss. Your application doesn’t need to know a thing; it just keeps using the same connection string. This is the magic you’re paying for.
# This connection is for making CHANGES. Handle with care.
import mysql.connector
config = {
'user': 'admin',
'password': 'correct-horse-battery-staple',
'host': 'my-aurora-cluster.cluster-xyz.us-east-1.rds.amazonaws.com', # Writer Endpoint
'database': 'my_app_db',
'raise_on_warnings': True
}
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
# This query goes to the primary instance
cursor.execute("UPDATE users SET last_login = NOW() WHERE id = %s", (user_id,))
cnx.commit()
Pitfall: The biggest mistake is using the writer endpoint for read operations. You’re sending all your read traffic to the one instance that is already busy handling writes. It’s like making the head chef also wait all the tables. It’s a fantastic way to create an unnecessary bottleneck on your primary node. Don’t do it.
The Reader Endpoint: Load-Balancing for Your Queries
This is the workhorse for your SELECT statements. The reader endpoint (my-cluster.cluster-ro-xyz.us-east-1.rds.amazonaws.com) is a smart, DNS-level load balancer. It automatically distributes connection requests across the entire pool of Aurora Replicas in your cluster.
Got 5 replicas? The reader endpoint will round-robin your connections between all five of them, effectively spreading out your read load. It’s a thing of beauty. You use this for any query that is read-only. This is the primary mechanism for scaling read performance horizontally.
# This connection is for READS only. Use it liberally.
import mysql.connector
config = {
'user': 'admin',
'password': 'correct-horse-battery-staple',
'host': 'my-aurora-cluster.cluster-ro-xyz.us-east-1.rds.amazonaws.com', # Reader Endpoint
'database': 'my_app_db',
'raise_on_warnings': True
}
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
# This query gets load-balanced to any available replica
cursor.execute("SELECT * FROM products WHERE stock > 0")
results = cursor.fetchall()
Pitfall & Edge Case: The reader endpoint is eventually consistent. Your write on the primary takes a moment to propagate to the replicas. If you write data and immediately try to read it via the reader endpoint, you might get stale data. For scenarios where you absolutely cannot tolerate that (e.g., reading a record immediately after creating it), you have two options: read from the writer endpoint for that specific query (ick) or use a…
Custom Endpoints: For When You Need to Get Fancy
This is where you can tell Aurora, “I know you’re smart, but I need more control.” Custom endpoints are user-defined aliases that you can point to a subset of your DB instances. You define the “who” and the “how” in the endpoint’s rules.
Why would you do this?
- Dedicated Reporting Replica: You have one monster
r5.16xlargeinstance for your heavy analytical queries and a bunch of smallerr5.largeinstances for your application’s reads. Create a custom endpoint calledreports-endpointthat only points to that one big instance. Your reporting tool connects there and doesn’t stomp all over your app’s performance. - Instance Role Separation: You can create an endpoint that connects to all instances except the writer. It’s a more explicit way to ensure read-only connections.
- Failover Priority: You can define the order in which instances are chosen for a custom endpoint, which is useful for defining a specific failover target.
You create these in the AWS Console, CLI, or CloudFormation. Here’s how you’d connect to one:
# Using the AWS CLI to create a custom endpoint for reporting
aws rds create-db-cluster-endpoint \
--db-cluster-identifier my-aurora-cluster \
--db-cluster-endpoint-identifier my-reports-endpoint \
--endpoint-type READER \
--static-members instance-1 instance-2
# Your reporting application now uses its dedicated endpoint
config['host'] = 'my-reports-endpoint.cluster-custom-xyz.us-east-1.rds.amazonaws.com'
Best Practice: Always, and I mean always, use these endpoint hostnames in your application configuration. Never hardcode the underlying instance’s individual endpoint. The instance endpoints are for diagnostics and emergencies. If you connect directly to a replica and it fails, your app breaks. If you connect to the reader endpoint and a replica fails, Aurora quietly routes you to a healthy one. It’s the difference between driving a car with a spare tire in the trunk and driving a car where the tire falls off and you have to pull over to put a new one on yourself. Use the endpoints. They exist to save you from yourself.