Type Annotations for boto3 CloudFormation

1.42.3 · active · verified Sat Apr 11

types-boto3-cloudformation provides type annotations for the `boto3` AWS SDK's CloudFormation service, compatible with static analysis tools like mypy, pyright, and IDEs such as VSCode and PyCharm. It is generated by the `mypy-boto3-builder` (currently version 8.12.0) and typically releases updates in sync with `boto3` to provide accurate type hints for the latest AWS service APIs. The current version of these annotations is 1.42.3, matching `boto3`'s version.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a typed CloudFormation client and use it to list stacks. The `TYPE_CHECKING` block ensures the type imports are only used during static analysis, avoiding a runtime dependency if desired. You must have AWS credentials configured for boto3 to function (e.g., via `~/.aws/credentials` or environment variables).

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from types_boto3_cloudformation.client import CloudFormationClient
    from types_boto3_cloudformation.type_defs import StackSummaryTypeDef

# Create a boto3 client. Types are typically auto-discovered by IDEs/type checkers
# if types-boto3-cloudformation is installed.
client: CloudFormationClient = boto3.client("cloudformation")

try:
    # Example: List CloudFormation stacks
    response = client.list_stacks(StackStatusFilter=[
        'CREATE_COMPLETE', 'UPDATE_COMPLETE', 'ROLLBACK_COMPLETE'
    ])

    print("CloudFormation Stacks:")
    for stack_summary: StackSummaryTypeDef in response.get("StackSummaries", []):
        print(f"  - {stack_summary['StackName']} ({stack_summary['StackStatus']})")

except Exception as e:
    print(f"Error listing stacks: {e}")
    # In a real application, handle specific AWS exceptions like ClientError

view raw JSON →