Skip to main content

This is a fork of aurora-data-api: https://github.com/chanzuckerberg/aurora-data-api

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. You can verify that everything works correctly by running a test query via the AWS CLI:

    aws rds-data execute-statement --resource-arn RESOURCE_ARN --secret-arn SECRET_ARN --sql "select * from pg_catalog.pg_tables"

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) * If not given as a keyword argument, this can also be specified using the AURORA_CLUSTER_ARN environment variable

  • secret_arn (the database credentials secret) * If not given as a keyword argument, this can also be specified using the AURORA_SECRET_ARN environment variable

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())

The cursor supports iteration (and automatically wraps the query in a server-side cursor and paginates it if required):

with conn.cursor() as cursor:
    for row in cursor.execute("select * from pg_catalog.pg_tables"):
        print(row)

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

License

Licensed under the terms of the Apache License, Version 2.0.

https://travis-ci.org/chanzuckerberg/aurora-data-api.png https://codecov.io/github/chanzuckerberg/aurora-data-api/coverage.svg?branch=master https://img.shields.io/pypi/v/aurora-data-api.svg https://img.shields.io/pypi/l/aurora-data-api.svg https://readthedocs.org/projects/aurora-data-api/badge/?version=latest

Metadata

Release files for serverless-aurora 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for serverless-aurora 0.2.3
File Size Uploaded Provenance Actions
serverless-aurora-0.2.3.tar.gz 20.2 kB Without provenance Details for serverless-aurora-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for serverless-aurora 0.2.3
File Interpreter ABI Platform Actions
serverless_aurora-0.2.3-py2.py3-none-any.whl Python 3, Python 2 none any Details for serverless_aurora-0.2.3-py2.py3-none-any.whl

Total release size: 40.6 kB

Release files / serverless-aurora-0.2.3.tar.gz

Download URL serverless-aurora-0.2.3.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
29c047f67fd9b7ec21c2fa8d51d48ca8a994529db1ae934256f21b3cb3932c9c
BLAKE2b-256 checksum
How to use checksums
d81607c75f060fdd434202ebbc040299c4aa69f2fc6f3be010739375821d16e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.5

Release files / serverless_aurora-0.2.3-py2.py3-none-any.whl

Download URL serverless_aurora-0.2.3-py2.py3-none-any.whl
Size 20.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3444c4647d4e11b73e601a9ead0f20aad3da57103063b93b1356a5ad8a3a1fdf
BLAKE2b-256 checksum
How to use checksums
db87d93e3ef081fda477eb945f557903f806f825112ca27a01184a5bafdea269
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.5

Security for serverless-aurora 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page