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.
from boto3.session import Session
session = Session()
client = session.client("cloudformation") # (1)
result = client.activate_type() # (2)
- client: CloudFormationClient
- result: ActivateTypeOutputTypeDef
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)
- client: CloudFormationClient
- paginator: DescribeAccountLimitsPaginator
- item: DescribeAccountLimitsOutputTypeDef
from boto3.session import Session
session = Session()
client = session.client("cloudformation") # (1)
waiter = client.get_waiter("change_set_create_complete") # (2)
waiter.wait()
- client: CloudFormationClient
- 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.
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)
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)
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.
from boto3.session import Session
session = Session()
resource = session.resource("cloudformation") # (1)
result = resource.Event() # (2)
- resource: CloudFormationServiceResource
- result:
from boto3.session import Session
session = Session()
resource = session.resource("cloudformation") # (1)
collection = resource.stacks # (2)
for item in collection:
print(item) # (3)
- resource: CloudFormationServiceResource
- collection: CloudFormationServiceResource
- 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.
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()
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)