|
| 1 | +# Aurora Global Databases |
| 2 | + |
| 3 | +The AWS Advanced Python Wrapper provides support for [Amazon Aurora Global Databases](https://aws.amazon.com/rds/aurora/global-database/). |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Aurora Global Database is a feature that allows a single Aurora database to span multiple AWS regions. It provides fast replication across regions with minimal impact on database performance, enabling disaster recovery and serving read traffic from multiple regions. |
| 8 | + |
| 9 | +The AWS Advanced Python Wrapper supports Global Writer Endpoint recognition. |
| 10 | + |
| 11 | +## Configuration |
| 12 | + |
| 13 | +The following instructions are recommended by AWS Service Teams for Aurora Global Database connections. |
| 14 | + |
| 15 | +### Writer Connections |
| 16 | + |
| 17 | +**Connection String:** |
| 18 | +Use the global cluster endpoint: |
| 19 | +``` |
| 20 | +<global-db-name>.global-<XYZ>.global.rds.amazonaws.com |
| 21 | +``` |
| 22 | + |
| 23 | +**Configuration Parameters:** |
| 24 | + |
| 25 | +| Parameter | Value | Notes | |
| 26 | +|------------------------------------------|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------| |
| 27 | +| `cluster_id` | `1` | See [cluster_id parameter documentation](./ClusterId.md) | |
| 28 | +| `wrapper_dialect` | `global-aurora-mysql` or `global-aurora-pg` | | |
| 29 | +| `plugins` | `initial_connection,failover2,efm2` | Without connection pooling | |
| 30 | +| | `aurora_connection_tracker,initial_connection,failover2,efm2` | With connection pooling | |
| 31 | +| `global_cluster_instance_host_patterns` | `us-east-2:?.XYZ1.us-east-2.rds.amazonaws.com,us-west-2:?.XYZ2.us-west-2.rds.amazonaws.com` | See [documentation](./using-plugins/UsingTheFailover2Plugin.md) | |
| 32 | + |
| 33 | +> **Note:** Add additional plugins as needed for your use case. |
| 34 | +
|
| 35 | +### Reader Connections |
| 36 | + |
| 37 | +**Connection String:** |
| 38 | +Use the cluster reader endpoint: |
| 39 | +``` |
| 40 | +<cluster-name>.cluster-ro-<XYZ>.<region>.rds.amazonaws.com |
| 41 | +``` |
| 42 | + |
| 43 | +**Configuration Parameters:** |
| 44 | + |
| 45 | +| Parameter | Value | Notes | |
| 46 | +|------------------------------------------|--------------------------------------------------------------------------------|------------------------------------------| |
| 47 | +| `cluster_id` | `1` | Use the same value as writer connections | |
| 48 | +| `wrapper_dialect` | `global-aurora-mysql` or `global-aurora-pg` | | |
| 49 | +| `plugins` | `initial_connection,failover2,efm2` | Without connection pooling | |
| 50 | +| | `aurora_connection_tracker,initial_connection,failover2,efm2` | With connection pooling | |
| 51 | +| `global_cluster_instance_host_patterns` | Same as writer configuration | | |
| 52 | +| `failover_mode` | `strict-reader` or `reader-or-writer` | Depending on system requirements | |
| 53 | + |
| 54 | +> **Note:** Add additional plugins as needed for your use case. |
| 55 | +
|
| 56 | +## Example Configuration |
| 57 | + |
| 58 | +### PostgreSQL Example |
| 59 | + |
| 60 | +```python |
| 61 | +from aws_advanced_python_wrapper import AwsWrapperConnection |
| 62 | +from psycopg import Connection |
| 63 | + |
| 64 | +# Writer connection |
| 65 | +with AwsWrapperConnection.connect( |
| 66 | + Connection.connect, |
| 67 | + "host=my-global-db.global-xyz.global.rds.amazonaws.com dbname=mydb user=admin password=pwd", |
| 68 | + plugins="initial_connection,failover2,efm2", |
| 69 | + wrapper_dialect="global-aurora-pg", |
| 70 | + cluster_id="1", |
| 71 | + global_cluster_instance_host_patterns="us-east-1:?.abc123.us-east-1.rds.amazonaws.com,us-west-2:?.def456.us-west-2.rds.amazonaws.com", |
| 72 | + autocommit=True |
| 73 | +) as awsconn: |
| 74 | + awscursor = awsconn.cursor() |
| 75 | + awscursor.execute("SELECT pg_catalog.aurora_db_instance_identifier()") |
| 76 | + print(awscursor.fetchone()) |
| 77 | + |
| 78 | +# Reader connection |
| 79 | +with AwsWrapperConnection.connect( |
| 80 | + Connection.connect, |
| 81 | + "host=my-cluster.cluster-ro-abc123.us-east-1.rds.amazonaws.com dbname=mydb user=admin password=pwd", |
| 82 | + plugins="initial_connection,failover2,efm2", |
| 83 | + wrapper_dialect="global-aurora-pg", |
| 84 | + cluster_id="1", |
| 85 | + global_cluster_instance_host_patterns="us-east-1:?.abc123.us-east-1.rds.amazonaws.com,us-west-2:?.def456.us-west-2.rds.amazonaws.com", |
| 86 | + failover_mode="strict-reader", |
| 87 | + autocommit=True |
| 88 | +) as awsconn: |
| 89 | + awscursor = awsconn.cursor() |
| 90 | + awscursor.execute("SELECT pg_catalog.aurora_db_instance_identifier()") |
| 91 | + print(awscursor.fetchone()) |
| 92 | +``` |
| 93 | + |
| 94 | +### MySQL Example |
| 95 | + |
| 96 | +```python |
| 97 | +from aws_advanced_python_wrapper import AwsWrapperConnection |
| 98 | +from mysql.connector import Connect |
| 99 | + |
| 100 | +# Writer connection |
| 101 | +with AwsWrapperConnection.connect( |
| 102 | + Connect, |
| 103 | + "host=my-global-db.global-xyz.global.rds.amazonaws.com database=mydb user=admin password=pwd", |
| 104 | + plugins="initial_connection,failover2,efm2", |
| 105 | + wrapper_dialect="global-aurora-mysql", |
| 106 | + cluster_id="1", |
| 107 | + global_cluster_instance_host_patterns="us-east-1:?.abc123.us-east-1.rds.amazonaws.com,us-west-2:?.def456.us-west-2.rds.amazonaws.com", |
| 108 | + autocommit=True |
| 109 | +) as awsconn: |
| 110 | + awscursor = awsconn.cursor() |
| 111 | + awscursor.execute("SELECT @@aurora_server_id") |
| 112 | + print(awscursor.fetchone()) |
| 113 | +``` |
| 114 | + |
| 115 | +## Important Considerations |
| 116 | + |
| 117 | +### Plugin Selection |
| 118 | +- **Connection Pooling**: Include the `aurora_connection_tracker` plugin when using connection pooling. |
| 119 | + |
| 120 | +### Global Cluster Instance Host Patterns |
| 121 | +The `global_cluster_instance_host_patterns` parameter is **required** for Aurora Global Databases. Each entry uses the format `<aws-region>:<host-pattern>` or `<aws-region>:<host-pattern>:<port>`. It should contain: |
| 122 | +- Comma-separated list of region-prefixed host patterns for each region |
| 123 | +- Different cluster identifiers for each region (e.g., `XYZ1`, `XYZ2`) |
| 124 | +- Example: `us-east-2:?.XYZ1.us-east-2.rds.amazonaws.com,us-west-2:?.XYZ2.us-west-2.rds.amazonaws.com` |
| 125 | + |
| 126 | +### Authentication Plugins Compatible with GDB |
| 127 | +- [IAM Authentication Plugin](./using-plugins/UsingTheIamAuthenticationPlugin.md) |
| 128 | +- [Federated Authentication Plugin](./using-plugins/UsingTheFederatedAuthPlugin.md) |
| 129 | +- [Okta Authentication Plugin](./using-plugins/UsingTheOktaAuthPlugin.md) |
0 commit comments