awswrangler.sqlserver.connect¶
- awswrangler.sqlserver.connect(connection: str | None = None, secret_id: str | None = None, catalog_id: str | None = None, dbname: str | None = None, odbc_driver_version: int = 17, boto3_session: Session | None = None, timeout: int | None = 0) pyodbc.Connection ¶
Return a pyodbc connection from a Glue Catalog Connection.
https://github.com/mkleehammer/pyodbc
Note
You MUST pass a connection OR secret_id. Here is an example of the secret structure in Secrets Manager: { “host”:”sqlserver-instance-wrangler.dr8vkeyrb9m1.us-east-1.rds.amazonaws.com”, “username”:”test”, “password”:”test”, “engine”:”sqlserver”, “port”:”1433”, “dbname”: “mydb” # Optional }
- Parameters:
connection (
str
|None
) – Glue Catalog Connection name.secret_id (
str
|None
) – Specifies the secret containing the connection details that you want to retrieve. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret.catalog_id (
str
|None
) – The ID of the Data Catalog. If none is provided, the AWS account ID is used by default.dbname (
str
|None
) – Optional database name to overwrite the stored one.odbc_driver_version (
int
) – Major version of the OBDC Driver version that is installed and should be used.boto3_session (
Session
|None
) – The default boto3 session will be used if boto3_session isNone
.timeout (
int
|None
) – This is the time in seconds before the connection to the server will time out. The default is None which means no timeout. This parameter is forwarded to pyodbc. https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#connect
- Return type:
Connection
- Returns:
pyodbc connection.
Examples
>>> import awswrangler as wr >>> with wr.sqlserver.connect(connection="MY_GLUE_CONNECTION", odbc_driver_version=17) as con: ... with con.cursor() as cursor: ... cursor.execute("SELECT 1") ... print(cursor.fetchall())