Type Annotations for boto3 DRS

1.42.86 · active · verified Sat Apr 11

mypy-boto3-drs provides comprehensive type annotations for the AWS Disaster Recovery Service (DRS) client within the boto3 library. Version 1.42.86 is currently available, generated by mypy-boto3-builder 8.12.0. The project maintains an active release cadence, frequently updating stubs to align with new boto3 and botocore versions, ensuring compatibility with popular type checkers like mypy and pyright, as well as IDEs like VSCode and PyCharm.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a typed DRS client using `mypy-boto3-drs` and `boto3`, and then perform a basic API call (`describe_recovery_instances`). It includes the recommended `TYPE_CHECKING` guard for conditional import of stubs and explicit type annotation for the client object.

from typing import TYPE_CHECKING
import boto3
import os

if TYPE_CHECKING:
    from mypy_boto3_drs import DRSClient
    from mypy_boto3_drs.type_defs import DescribeRecoveryInstancesResponseTypeDef

# Configure AWS credentials and region, e.g., via environment variables or ~/.aws/credentials
# For quickstart, ensure default session is configured or pass explicit creds/region.

def get_drs_recovery_instances() -> None:
    # Explicitly type the client for mypy/IDE support
    client: DRSClient = boto3.client("drs", region_name=os.environ.get("AWS_REGION", "us-east-1"))
    
    try:
        # Example: Describe recovery instances
        response: DescribeRecoveryInstancesResponseTypeDef = client.describe_recovery_instances()
        
        print(f"Found {len(response['items'])} DRS Recovery Instances:")
        for instance in response['items']:
            print(f"  - Instance ID: {instance.get('recoveryInstanceID')}, Status: {instance.get('lifeCycle', {}).get('status')}")

    except Exception as e:
        print(f"Error describing DRS recovery instances: {e}")

if __name__ == "__main__":
    # Set dummy values for AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION if not configured
    os.environ.setdefault('AWS_ACCESS_KEY_ID', 'testing')
    os.environ.setdefault('AWS_SECRET_ACCESS_KEY', 'testing')
    os.environ.setdefault('AWS_REGION', 'us-east-1')
    get_drs_recovery_instances()

view raw JSON →