Type Annotations for boto3 MigrationHubConfig
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
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and subsequent package releases. Users on Python 3.8 must upgrade their Python version to 3.9 or newer.
- gotcha These packages provide type stubs for boto3; `boto3` itself must be installed separately for runtime functionality. Failing to install `boto3` will result in runtime `ModuleNotFoundError`.
- gotcha For optimal static analysis and IDE autocomplete (especially in VSCode), explicitly type the `boto3.client()` call with the imported client type (e.g., `client: MigrationHubConfigClient = boto3.client(...)`). Implicit typing may not provide full benefits.
- breaking In `mypy-boto3-builder` 8.9.0, there were changes to how TypeDef names for packed method arguments are generated (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If you were explicitly importing and using such TypeDefs, their names might have changed.
- gotcha Using these type stubs with linters like Pylint or Flake8 can sometimes lead to 'undefined variable' or 'unused import' warnings when `TYPE_CHECKING` guards are not used. These stubs are only for static analysis, not runtime.
Install
-
pip install mypy-boto3-migrationhub-config boto3 mypy
Imports
- MigrationHubConfigClient
from mypy_boto3_migrationhub_config.client import MigrationHubConfigClient
- GetHomeRegionResultTypeDef
from mypy_boto3_migrationhub_config.type_defs import GetHomeRegionResultTypeDef
Quickstart
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()