Skip to content

Examples#

Index > CloudFormation > Examples

Auto-generated documentation for CloudFormation type annotations stubs module mypy-boto3-cloudformation.

Client#

Implicit type annotations#

Can be used with boto3-stubs[cloudformation] package installed.

Write your CloudFormation code as usual, type checking and code completion should work out of the box.

# CloudFormationClient usage example

from boto3.session import Session


session = Session()

client = session.client("cloudformation")  # (1)
result = client.activate_type()  # (2)
  1. client: CloudFormationClient
  2. result: ActivateTypeOutputTypeDef
# DescribeAccountLimitsPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("cloudformation")  # (1)

paginator = client.get_paginator("describe_account_limits")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: CloudFormationClient
  2. paginator: DescribeAccountLimitsPaginator
  3. item: DescribeAccountLimitsOutputTypeDef
# ChangeSetCreateCompleteWaiter usage example

from boto3.session import Session


session = Session()
client = session.client("cloudformation")  # (1)

waiter = client.get_waiter("change_set_create_complete")  # (2)
waiter.wait()
  1. client: CloudFormationClient
  2. waiter: ChangeSetCreateCompleteWaiter

Explicit type annotations#

With boto3-stubs-lite[cloudformation] or a standalone mypy_boto3_cloudformation package, you have to explicitly specify client: CloudFormationClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# CloudFormationClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_cloudformation.client import CloudFormationClient
from mypy_boto3_cloudformation.type_defs import ActivateTypeOutputTypeDef
from mypy_boto3_cloudformation.type_defs import ActivateTypeInputRequestTypeDef


session = Session()

client: CloudFormationClient = session.client("cloudformation")

kwargs: ActivateTypeInputRequestTypeDef = {...}
result: ActivateTypeOutputTypeDef = client.activate_type(**kwargs)
# DescribeAccountLimitsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_cloudformation.client import CloudFormationClient
from mypy_boto3_cloudformation.paginator import DescribeAccountLimitsPaginator
from mypy_boto3_cloudformation.type_defs import DescribeAccountLimitsOutputTypeDef


session = Session()
client: CloudFormationClient = session.client("cloudformation")

paginator: DescribeAccountLimitsPaginator = client.get_paginator("describe_account_limits")
for item in paginator.paginate(...):
    item: DescribeAccountLimitsOutputTypeDef
    print(item)
# ChangeSetCreateCompleteWaiter usage example with type annotations

from boto3.session import Session

from mypy_boto3_cloudformation.client import CloudFormationClient
from mypy_boto3_cloudformation.waiter import ChangeSetCreateCompleteWaiter

session = Session()
client: CloudFormationClient = session.client("cloudformation")

waiter: ChangeSetCreateCompleteWaiter = client.get_waiter("change_set_create_complete")
waiter.wait()

Service Resource#

Implicit type annotations#

Can be used with boto3-stubs[cloudformation] package installed.

# CloudFormationServiceResource usage example

from boto3.session import Session


session = Session()

resource = session.resource("cloudformation")  # (1)
result = resource.Event()  # (2)
  1. resource: CloudFormationServiceResource
  2. result:
# ServiceResourceStacksCollection usage example

from boto3.session import Session


session = Session()
resource = session.resource("cloudformation")  # (1)

collection = resource.stacks  # (2)
for item in collection:
    print(item)  # (3)
  1. resource: CloudFormationServiceResource
  2. collection: CloudFormationServiceResource
  3. item: Stack

Explicit type annotations#

With boto3-stubs-lite[cloudformation] or a standalone mypy_boto3_cloudformation package, you have to explicitly specify resource: CloudFormationServiceResource type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# CloudFormationServiceResource usage example with type annotations

from boto3.session import Session

from mypy_boto3_cloudformation.service_resource import CloudFormationServiceResource
from mypy_boto3_cloudformation.service_resource import Event


session = Session()

resource: CloudFormationServiceResource = session.resource("cloudformation")
result: Event = resource.Event()
# ServiceResourceStacksCollection usage example with type annotations

from boto3.session import Session

from mypy_boto3_cloudformation.service_resource import CloudFormationServiceResource
from mypy_boto3_cloudformation.service_resource import ServiceResourceStacksCollection
from mypy_boto3_cloudformation.service_resource import Stack


session = Session()

resource: CloudFormationServiceResource = session.resource("cloudformation")

collection: ServiceResourceStacksCollection = resource.stacks
for item in collection:
    item: Stack
    print(item)