mypy-boto3-cloudcontrol: Type Annotations for AWS Cloud Control API

1.42.3 · active · verified Sat Apr 11

mypy-boto3-cloudcontrol provides type annotations for the AWS boto3 CloudControlApi service. It is part of the larger `mypy-boto3-builder` ecosystem, which generates stubs for all boto3 services. This specific package, currently at version 1.42.3, helps static type checkers like Mypy understand the dynamic nature of boto3 clients, offering improved code completion, error detection, and overall developer experience for Cloud Control API interactions. The builder project releases frequently, often synchronizing with `boto3` and `botocore` updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-cloudcontrol` for type hinting an AWS Cloud Control API client. It shows importing the `CloudControlClient` type within a `TYPE_CHECKING` block to ensure `mypy-boto3-cloudcontrol` is only a development dependency. The `boto3` runtime client is then instantiated and passed to a function with explicit type hints, enabling static analysis by `mypy`.

from typing import TYPE_CHECKING
import boto3
import os

# Only import type stubs when type checking
if TYPE_CHECKING:
    from mypy_boto3_cloudcontrol.client import CloudControlClient
    from mypy_boto3_cloudcontrol.type_defs import ListResourcesOutputTypeDef


def list_cloud_control_resources(client: 'CloudControlClient') -> 'ListResourcesOutputTypeDef':
    """Lists resources managed by AWS Cloud Control API."""
    # Example: List up to 10 resources of a specific type
    # Replace 'AWS::S3::Bucket' with an actual resource type if needed
    response = client.list_resources(
        TypeName='AWS::S3::Bucket', # Use a valid AWS resource type
        MaxResults=10
    )
    print(f"Found {len(response.get('ResourceDescriptions', []))} resources.")
    for resource in response.get('ResourceDescriptions', []):
        print(f"  - ID: {resource.get('Identifier')}, Name: {resource.get('ResourceModel')}")
    return response

if __name__ == "__main__":
    # Ensure AWS credentials are configured (e.g., via environment variables or AWS CLI)
    # This is a runtime client, not directly from mypy-boto3-cloudcontrol
    session = boto3.Session(
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
        aws_session_token=os.environ.get('AWS_SESSION_TOKEN', ''),
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )
    cloudcontrol_client: 'CloudControlClient' = session.client("cloudcontrol")
    
    try:
        list_cloud_control_resources(cloudcontrol_client)
    except Exception as e:
        print(f"An error occurred: {e}")
        print("Make sure 'AWS::S3::Bucket' (or chosen TypeName) is a valid and accessible resource type.")

# To run mypy:
# mypy your_script_name.py

view raw JSON →