Type Annotations for boto3 MigrationHubConfig

1.42.3 · active · verified Sat Apr 11

Provides type annotations for the `boto3` AWS Migration Hub Config service, enhancing static analysis with tools like MyPy, VSCode, and PyCharm. It helps with code completion, argument checking, and catching potential runtime errors at development time. The current version is 1.42.3, generated with `mypy-boto3-builder 8.12.0`, and it follows the release cadence of `boto3`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a typed `MigrationHubConfigClient` and use it to retrieve the Migration Hub home region. It includes explicit type hints for `boto3.client` and for the response type, which is crucial for full static analysis and IDE autocomplete. Ensure `boto3` and `mypy-boto3-migrationhub-config` are installed, and AWS credentials are configured.

import boto3
from typing import TYPE_CHECKING, Dict, Any
from os import environ

if TYPE_CHECKING:
    from mypy_boto3_migrationhub_config.client import MigrationHubConfigClient
    from mypy_boto3_migrationhub_config.type_defs import GetHomeRegionResultTypeDef

def get_migrationhub_config_client() -> "MigrationHubConfigClient":
    """
    Returns a typed MigrationHubConfig client.
    """
    region = environ.get("AWS_REGION", "us-east-1") # Default region if not set
    client: "MigrationHubConfigClient" = boto3.client("migrationhub-config", region_name=region)
    return client

def describe_current_home_region():
    """
    Describes the current Migration Hub home region.
    """
    client = get_migrationhub_config_client()
    try:
        response: "GetHomeRegionResultTypeDef" = client.get_home_region()
        home_region = response.get("HomeRegion")
        print(f"Current Migration Hub Home Region: {home_region}")
        return home_region
    except client.exceptions.AccessDeniedException:
        print("Access Denied: Ensure your AWS credentials are configured and have permissions for migrationhub-config:GetHomeRegion.")
        return None
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
        return None

if __name__ == "__main__":
    # Set AWS credentials and region via environment variables (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
    # or AWS CLI configuration before running.
    print("Attempting to retrieve Migration Hub Home Region...")
    describe_current_home_region()

view raw JSON →