mypy-boto3-cloudformation

1.42.3 · active · verified Thu Apr 09

mypy-boto3-cloudformation provides type annotations for the boto3 CloudFormation service. It is automatically generated by mypy-boto3-builder and closely follows boto3's versioning, offering up-to-date type stubs for improved static analysis and IDE assistance when working with AWS CloudFormation using boto3. The library is actively maintained with frequent updates reflecting changes in boto3 and the AWS API.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted CloudFormation client from boto3 and perform a basic operation like listing stacks. It shows how to use the `CloudFormationClient` type for the client object and `StackSummaryTypeDef` for processing response data, ensuring static type checking of your boto3 interactions.

import boto3
from mypy_boto3_cloudformation.client import CloudFormationClient
from mypy_boto3_cloudformation.type_defs import StackSummaryTypeDef
from mypy_boto3_cloudformation import CloudFormationServiceName

# Get a typed CloudFormation client using CloudFormationServiceName for safety
client: CloudFormationClient = boto3.client(CloudFormationServiceName.CLOUDFORMATION)

# Example: List stacks and iterate with type hints
try:
    response = client.list_stacks(StackStatusFilter=['CREATE_COMPLETE', 'UPDATE_COMPLETE'])
    
    # response['StackSummaries'] is a list of StackSummaryTypeDef
    stacks: list[StackSummaryTypeDef] = response.get('StackSummaries', [])

    if stacks:
        print("CloudFormation Stacks:")
        for stack in stacks:
            print(f"  Name: {stack['StackName']}, Status: {stack['StackStatus']}, Id: {stack['StackId']}")
    else:
        print("No CREATE_COMPLETE or UPDATE_COMPLETE stacks found.")
except Exception as e:
    print(f"Error listing stacks: {e}")

# The type checker (e.g., mypy) will now validate usage of `client`
# and `stack` objects against the CloudFormation API definition.

view raw JSON →