Skip to content

generate_db_auth_token async

generate_db_auth_token(
    *,
    hostname: str,
    port: int,
    username: str,
    config_overrides: AsyncRDSClientConfig | None = None,
) -> str

An IAM authentication token to connect to an RDS or Aurora database as username: pass it as the password, over TLS. It is valid for 15 minutes, and signed locally with the client's credentials and region, so nothing is sent to AWS.

Parameters:

  • hostname (str) –

    The database's endpoint, such as mydb.123456789012.us-east-1.rds.amazonaws.com.

  • port (int) –

    The port the database listens on, such as 5432.

  • username (str) –

    A database user set up for IAM authentication.

  • config_overrides (AsyncRDSClientConfig | None, default: None ) –

    Client settings for this call only, such as another region or credentials_provider.

Source code in docs_src/capo_rds/_services/async_rds.py
async def generate_db_auth_token(
    self,
    *,
    hostname: str,
    port: int,
    username: str,
    config_overrides: AsyncRDSClientConfig | None = None,
) -> str:
    """An IAM authentication token to connect to an RDS or Aurora database as ``username``: pass it as the password, over TLS. It is valid for 15 minutes, and signed locally with the client's credentials and region, so nothing is sent to AWS.

    Args:
        hostname: The database's endpoint, such as ``mydb.123456789012.us-east-1.rds.amazonaws.com``.
        port: The port the database listens on, such as ``5432``.
        username: A database user set up for IAM authentication.
        config_overrides: Client settings for this call only, such as another ``region`` or ``credentials_provider``.
    """
    _, options_ = self.operation_options(config_overrides)
    # Where an API call would take the region from: the client, else AWS_REGION or the profile
    region = options_.region or load_aws_settings().region
    if region is None:
        raise ValueError("an auth token needs a region: pass region= to the client")
    provider = options_.credentials_provider
    if provider is None:
        raise RuntimeError("an auth token needs credentials")
    credentials = await provider.aresolve_identity()
    return presign_auth_token(
        f"{hostname}:{port}",
        {"Action": "connect", "DBUser": username},
        credentials=credentials,
        region=region,
        signing_name="rds-db",
        expires_in=900,
    )