A Python DB-API 2.0 client for the AWS Aurora Serverless Data API
Project description
Installation
pip install aurora-data-api
Prerequisites
Set up an AWS Aurora Serverless cluster and enable Data API access for it. If you have previously set up an Aurora Serverless cluster, you can enable Data API with the following AWS CLI command:
aws rds modify-db-cluster --db-cluster-identifier DB_CLUSTER_NAME --enable-http-endpoint --apply-immediately
Save the database credentials in AWS Secrets Manager using a format expected by the Data API (a JSON object with the keys username and password):
aws secretsmanager put-secret-value --secret-id MY_DB_CREDENTIALS --secret-string "$(jq -n '.username=env.PGUSER | .password=env.PGPASSWORD')"
Configure your AWS command line credentials using standard AWS conventions.
Usage
Use this module as you would use any DB-API compatible driver module. The aurora_data_api.connect() method is the standard main entry point, and accepts two implementation-specific keyword arguments:
aurora_cluster_arn (also referred to as resourceArn in the Data API documentation)
secret_arn (the database credentials secret)
import aurora_data_api
cluster_arn = "arn:aws:rds:us-east-1:123456789012:cluster:my-aurora-serverless-cluster"
secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:MY_DB_CREDENTIALS"
with aurora_data_api.connect(aurora_cluster_arn=cluster_arn, secret_arn=secret_arn, database="my_db") as conn:
with conn.cursor() as cursor:
cursor.execute("select * from pg_catalog.pg_tables")
print(cursor.fetchall())
Motivation
The RDS Data API is the link between the AWS Lambda serverless environment and the sophisticated features provided by PostgreSQL and MySQL. The Data API tunnels SQL over HTTP, which has advantages in the context of AWS Lambda:
It eliminates the need to open database ports to the AWS Lambda public IP address pool
It uses stateless HTTP connections instead of stateful internal TCP connection pools used by most database drivers (the stateful pools become invalid after going through AWS Lambda freeze-thaw cycles, causing connection errors and burdening the database server with abandoned invalid connections)
It uses AWS role-based authentication, eliminating the need for the Lambda to handle database credentials directly
Links
Bugs
Please report bugs, issues, feature requests, etc. on GitHub.
License
Licensed under the terms of the Apache License, Version 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aurora-data-api-0.0.2.tar.gz
.
File metadata
- Download URL: aurora-data-api-0.0.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a40268fea9977b88438b040d8939da04aabe3d97cdeb0b79a43a25b9bbf4553 |
|
MD5 | 0d9b09580e2ed412a805327a9c9c1c74 |
|
BLAKE2b-256 | 51409d546ae97a33ed9e85acb16a5967610a53719f63037ac1853bd8234890a7 |
File details
Details for the file aurora_data_api-0.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: aurora_data_api-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b38d19713233d8040a920c2e65d4d2232c793a2547d73a19a880fc4bc70e7835 |
|
MD5 | 12e09e549239b25ac419aa69832719bb |
|
BLAKE2b-256 | 4571d4cc8819bb5cfb203ef722bcc38af0cb0d8188840c28d9202bc63c45caab |