Type Annotations for boto3 Control Tower
mypy-boto3-controltower provides comprehensive type annotations for the `boto3` AWS Control Tower service client. It enhances the development experience by enabling static type checking with tools like `mypy` for `boto3` operations, catching potential errors at development time. This package provides stubs for `boto3` version 1.42.3 and is part of the `mypy-boto3-builder` ecosystem, which actively generates stubs for all `boto3` services. It is actively maintained with frequent updates reflecting `boto3` changes.
Warnings
- breaking Support for Python 3.8 was removed starting with version 8.12.0 of `mypy-boto3-builder` (which this package is part of).
- breaking Version 8.9.0 introduced breaking changes to `TypeDef` naming conventions across services (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef` by removing redundant `Request` postfix).
- gotcha These `mypy-boto3-*` packages provide only type annotations and do not add any runtime functionality to `boto3`. They are solely for static analysis tools like `mypy`.
- gotcha AWS service names can change or be deprecated (e.g., `sms-voice` changed to `pinpoint-sms-voice` in a previous release). Ensure you are using the correct and current service name string for `boto3.client()`.
Install
-
pip install mypy-boto3-controltower boto3
Imports
- ControlTowerClient
from mypy_boto3_controltower.client import ControlTowerClient
- ListControlTowerResourcesOutputTypeDef
from mypy_boto3_controltower.type_defs import ListControlTowerResourcesOutputTypeDef
Quickstart
import boto3
from mypy_boto3_controltower.client import ControlTowerClient
from mypy_boto3_controltower.type_defs import ListControlTowerResourcesOutputTypeDef
# Get a typed client for Control Tower
# Ensure AWS credentials are configured (e.g., via ~/.aws/credentials or environment variables)
# For local testing, ensure your default region is set.
client: ControlTowerClient = boto3.client("controltower")
# Example: List Control Tower resources with type hints
try:
print("Attempting to list Control Tower resources...")
response: ListControlTowerResourcesOutputTypeDef = client.list_control_tower_resources(
# You can add filters or pagination parameters here if needed
# max_results=5
)
resources = response.get('controlTowerResources', [])
if resources:
print(f"Found {len(resources)} Control Tower resources:")
for resource in resources:
print(f" - ARN: {resource.get('arn')}, Type: {resource.get('resourceType')}")
else:
print("No Control Tower resources found or access is restricted.")
except client.exceptions.AccessDeniedException:
print("Access Denied: Ensure your AWS credentials have sufficient permissions for Control Tower (e.g., 'controltower:ListControlTowerResources').")
except Exception as e:
print(f"An error occurred: {e}")