mypy-boto3-cloudsearchdomain Type Stubs for AWS CloudSearchDomain

1.42.3 · active · verified Sat Apr 11

This library provides type annotations for the `boto3` CloudSearchDomain service (version 1.42.3), generated by `mypy-boto3-builder` 8.12.0. It allows static type checking with tools like MyPy, enhancing code quality and developer experience when working with AWS CloudSearchDomain using `boto3`. The package closely follows `boto3` releases, offering frequent updates to maintain compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted `CloudSearchDomainClient` and perform a basic search operation. Note that the CloudSearchDomain client typically requires a specific `endpoint_url` for operations like `search` and `upload_documents`. In a production environment, this endpoint is usually discovered via the `cloudsearch` configuration service. The example includes placeholders for the endpoint and highlights common setup requirements.

import os
import boto3
from mypy_boto3_cloudsearchdomain import CloudSearchDomainClient

# The CloudSearchDomain client often requires an explicit endpoint_url.
# In a real application, you would retrieve this dynamically from
# boto3.client("cloudsearch").describe_domains().
# Replace with your actual CloudSearch domain search endpoint URL or set as env var.
CLOUDSEARCH_DOMAIN_ENDPOINT = os.environ.get(
    "CLOUDSEARCH_DOMAIN_ENDPOINT", 
    "https://search-your-domain-xyz.us-east-1.cloudsearch.amazonaws.com" # Placeholder
)

try:
    # Create a type-hinted CloudSearchDomain client
    client: CloudSearchDomainClient = boto3.client(
        "cloudsearchdomain",
        endpoint_url=CLOUDSEARCH_DOMAIN_ENDPOINT,
        # region_name=os.environ.get("AWS_REGION", "us-east-1") # Optional
    )

    # Perform a dummy search operation (requires a valid domain and query)
    # This call will likely fail if CLOUDSEARCH_DOMAIN_ENDPOINT is not valid or domain is empty.
    response = client.search(
        query="example",
        queryParser="simple"
    )

    print(f"Search found {response.get('hits', {}).get('found', 0)} items.")
    # Further operations with type-checked client...

except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure 'CLOUDSEARCH_DOMAIN_ENDPOINT' is set to a valid CloudSearch domain search endpoint.")
    print("You might need to use `boto3.client('cloudsearch').describe_domains()` to obtain it.")
    print("Also, verify AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials).")

view raw JSON →