Skip to content

Commit 8e7e0f7

Browse files
authored
docs: format srw examples (#1064)
1 parent 9408398 commit 8e7e0f7

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

docs/examples/MySQLReadWriteSplitting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from aws_advanced_python_wrapper.hostinfo import HostInfo
2121
from aws_advanced_python_wrapper.pep249 import Connection
2222

23-
import mysql.connector # type: ignore
23+
import mysql.connector # type: ignore
2424

2525
from aws_advanced_python_wrapper import AwsWrapperConnection
2626
from aws_advanced_python_wrapper.connection_provider import \

docs/examples/MySQLSimpleReadWriteSplitting.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union
17+
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union
1818

1919
if TYPE_CHECKING:
2020
from aws_advanced_python_wrapper.pep249 import Connection
2121

22-
import mysql.connector # type: ignore
22+
import mysql.connector # type: ignore
2323

2424
from aws_advanced_python_wrapper import AwsWrapperConnection
2525
from aws_advanced_python_wrapper.errors import (
2626
FailoverFailedError, FailoverSuccessError,
2727
TransactionResolutionUnknownError)
2828

29+
2930
def configure_initial_session_states(conn: Connection):
3031
awscursor = conn.cursor()
3132
awscursor.execute("SET time_zone = 'UTC'")
@@ -60,15 +61,15 @@ def execute_queries_with_failover_handling(conn: Connection, sql: str, params: O
6061

6162

6263
if __name__ == "__main__":
63-
params = {
64+
params: Any = {
6465
"host": "rds-proxy-name.proxy-xyz.us-east-1.rds.amazonaws.com",
6566
"database": "mysql",
6667
"user": "admin",
67-
"password": "pwd",
68+
"password": "pwd",
6869
"plugins": "srw,failover",
69-
"srw_write_endpoint": "rds-proxy-name.proxy-xyz.us-east-1.rds.amazonaws.com", # Replace with write endpoint
70-
"srw_read_endpoint": "rds-proxy-name-read-only.endpoint.proxy-xyz.us-east-1.rds.amazonaws.com", # Replace with read endpoint
71-
"srw_verify_new_connections": "True", # Enables role-verification for new endpoints
70+
"srw_write_endpoint": "rds-proxy-name.proxy-xyz.us-east-1.rds.amazonaws.com",
71+
"srw_read_endpoint": "rds-proxy-name-read-only.endpoint.proxy-xyz.us-east-1.rds.amazonaws.com",
72+
"srw_verify_new_connections": "True",
7273
"wrapper_dialect": "aurora-mysql",
7374
"autocommit": True,
7475
}

docs/examples/PGReadWriteSplitting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from aws_advanced_python_wrapper.hostinfo import HostInfo
2121
from aws_advanced_python_wrapper.pep249 import Connection
2222

23-
import psycopg # type: ignore
23+
import psycopg # type: ignore
2424

2525
from aws_advanced_python_wrapper import AwsWrapperConnection
2626
from aws_advanced_python_wrapper.connection_provider import \

docs/examples/PGSimpleReadWriteSplitting.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union
17+
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union
1818

1919
if TYPE_CHECKING:
2020
from aws_advanced_python_wrapper.pep249 import Connection
2121

22-
import psycopg # type: ignore
22+
import psycopg # type: ignore
2323

2424
from aws_advanced_python_wrapper import AwsWrapperConnection
2525
from aws_advanced_python_wrapper.errors import (
2626
FailoverFailedError, FailoverSuccessError,
2727
TransactionResolutionUnknownError)
28-
from aws_advanced_python_wrapper.host_monitoring_plugin import MonitoringThreadContainer
28+
2929

3030
def configure_initial_session_states(conn: Connection):
3131
awscursor = conn.cursor()
@@ -61,15 +61,15 @@ def execute_queries_with_failover_handling(conn: Connection, sql: str, params: O
6161

6262

6363
if __name__ == "__main__":
64-
params = {
64+
params: Any = {
6565
"host": "rds-proxy-name.proxy-xyz.us-east-1.rds.amazonaws.com",
6666
"dbname": "postgres",
6767
"user": "john",
6868
"password": "pwd",
6969
"plugins": "srw,failover",
70-
"srw_write_endpoint": "rds-proxy-name.proxy-xyz.us-east-1.rds.amazonaws.com", # Replace with write endpoint
71-
"srw_read_endpoint": "rds-proxy-name-read-only.endpoint.proxy-xyz.us-east-1.rds.amazonaws.com", # Replace with read endpoint
72-
"srw_verify_new_connections": "True", # Enables role-verification for new endpoints
70+
"srw_write_endpoint": "rds-proxy-name.proxy-xyz.us-east-1.rds.amazonaws.com",
71+
"srw_read_endpoint": "rds-proxy-name-read-only.endpoint.proxy-xyz.us-east-1.rds.amazonaws.com",
72+
"srw_verify_new_connections": "True",
7373
"wrapper_dialect": "aurora-pg",
7474
"autocommit": True,
7575
}

docs/using-the-python-driver/using-plugins/UsingTheSimpleReadWriteSplittingPlugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ When connecting with custom endpoints and other non-standard URLs, role verifica
5454
## Limitations When Verifying Connections
5555

5656
#### Non-RDS clusters
57-
The verification step determines the role of the connection by executing a query against it. If the endpoint is not part of an Aurora or RDS cluster, the plugin will not be able to verify the role, so `srw_verify_new_connections` *must* be set to `False`.
57+
The verification step determines the role of the connection by executing a query against it. The AWS Advanced Python Driver does not support gathering such information for databases that are not Aurora or RDS clusters. Thus, when connecting to non-RDS clusters `verifyNewSrwConnections` must be set to `false`.
5858

5959
#### Autocommit
6060
The verification logic results in errors such as `Cannot change transaction read-only property in the middle of a transaction` from the underlying driver when:

0 commit comments

Comments
 (0)