Type annotations for aiobotocore CloudFormation

3.4.0 · active · verified Sat Apr 11

Type annotations for aiobotocore CloudFormation 3.4.0 service. It provides comprehensive type hints for `aiobotocore` clients, paginators, waiters, and TypeDefs for the AWS CloudFormation service, compatible with static type checkers like mypy and pyright. The package is generated by the `mypy-boto3-builder` (version 8.12.0) and is released frequently, mirroring `aiobotocore` versions to ensure up-to-date type definitions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a typed `CloudFormationClient` using `aiobotocore` and interact with the CloudFormation service to list stacks. The `TYPE_CHECKING` block ensures that the explicit type imports for `CloudFormationClient` and `StackSummaryTypeDef` are only used during type checking, avoiding a runtime dependency on the stub package.

import asyncio
import os
from typing import TYPE_CHECKING

import aiobotocore.session

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


async def list_cloudformation_stacks():
    session = aiobotocore.session.get_session()
    async with session.create_client(
        "cloudformation",
        region_name=os.environ.get('AWS_REGION', 'us-east-1'),
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'testing'),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'testing')
    ) as client:
        # The client variable is automatically type-hinted as CloudFormationClient
        client: "CloudFormationClient"
        response = await client.list_stacks()

        for stack in response.get("StackSummaries", []):
            stack_summary: "StackSummaryTypeDef" = stack
            print(f"Stack Name: {stack_summary['StackName']}, Status: {stack_summary['StackStatus']}")


if __name__ == "__main__":
    asyncio.run(list_cloudformation_stacks())

view raw JSON →