Type Annotations for boto3 Control Tower

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

Demonstrates how to obtain a type-hinted Control Tower client and use it to list resources. This setup allows `mypy` and other type checkers to perform static analysis on your `boto3` Control Tower code, catching potential errors at development time.

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}")

view raw JSON →