Examples#
Index > CloudWatch > Examples
Auto-generated documentation for CloudWatch type annotations stubs module mypy-boto3-cloudwatch.
Client#
Implicit type annotations#
Can be used with boto3-stubs[cloudwatch]
package installed.
Write your CloudWatch
code as usual,
type checking and code completion should work out of the box.
Client method usage example#
# CloudWatchClient usage example
from boto3.session import Session
session = Session()
client = session.client("cloudwatch") # (1)
result = client.delete_alarms() # (2)
- client: CloudWatchClient
- result: EmptyResponseMetadataTypeDef
Paginator usage example#
# DescribeAlarmHistoryPaginator usage example
from boto3.session import Session
session = Session()
client = session.client("cloudwatch") # (1)
paginator = client.get_paginator("describe_alarm_history") # (2)
for item in paginator.paginate(...):
print(item) # (3)
- client: CloudWatchClient
- paginator: DescribeAlarmHistoryPaginator
- item: DescribeAlarmHistoryOutputTypeDef
Waiter usage example#
# AlarmExistsWaiter usage example
from boto3.session import Session
session = Session()
client = session.client("cloudwatch") # (1)
waiter = client.get_waiter("alarm_exists") # (2)
waiter.wait(...)
- client: CloudWatchClient
- waiter: AlarmExistsWaiter
Explicit type annotations#
With boto3-stubs-lite[cloudwatch]
or a standalone mypy_boto3_cloudwatch
package, you have to explicitly specify client: CloudWatchClient
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.
Client method usage example#
# CloudWatchClient usage example with type annotations
from boto3.session import Session
from mypy_boto3_cloudwatch.client import CloudWatchClient
from mypy_boto3_cloudwatch.type_defs import EmptyResponseMetadataTypeDef
from mypy_boto3_cloudwatch.type_defs import DeleteAlarmsInputTypeDef
session = Session()
client: CloudWatchClient = session.client("cloudwatch")
kwargs: DeleteAlarmsInputTypeDef = {...}
result: EmptyResponseMetadataTypeDef = client.delete_alarms(**kwargs)
Paginator usage example#
# DescribeAlarmHistoryPaginator usage example with type annotations
from boto3.session import Session
from mypy_boto3_cloudwatch.client import CloudWatchClient
from mypy_boto3_cloudwatch.paginator import DescribeAlarmHistoryPaginator
from mypy_boto3_cloudwatch.type_defs import DescribeAlarmHistoryOutputTypeDef
session = Session()
client: CloudWatchClient = session.client("cloudwatch")
paginator: DescribeAlarmHistoryPaginator = client.get_paginator("describe_alarm_history")
for item in paginator.paginate(...):
item: DescribeAlarmHistoryOutputTypeDef
print(item)
Waiter usage example#
# AlarmExistsWaiter usage example with type annotations
from boto3.session import Session
from mypy_boto3_cloudwatch.client import CloudWatchClient
from mypy_boto3_cloudwatch.waiter import AlarmExistsWaiter
session = Session()
client: CloudWatchClient = session.client("cloudwatch")
waiter: AlarmExistsWaiter = client.get_waiter("alarm_exists")
waiter.wait(...)
Service Resource#
Implicit type annotations#
Can be used with boto3-stubs[cloudwatch]
package installed.
Collection usage example#
# ServiceResourceAlarmsCollection usage example
from boto3.session import Session
session = Session()
resource = session.resource("cloudwatch") # (1)
collection = resource.alarms # (2)
for item in collection:
print(item) # (3)
- resource: CloudWatchServiceResource
- collection: ServiceResourceAlarmsCollection
- item: Alarm
Explicit type annotations#
With boto3-stubs-lite[cloudwatch]
or a standalone mypy_boto3_cloudwatch
package, you have to explicitly specify
resource: CloudWatchServiceResource
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.
Collection usage example#
# ServiceResourceAlarmsCollection usage example with type annotations
from boto3.session import Session
from mypy_boto3_cloudwatch.service_resource import CloudWatchServiceResource
from mypy_boto3_cloudwatch.service_resource import ServiceResourceAlarmsCollection
from mypy_boto3_cloudwatch.service_resource import Alarm
session = Session()
resource: CloudWatchServiceResource = session.resource("cloudwatch") # (1)
collection: ServiceResourceAlarmsCollection = resource.alarms # (2)
for item in collection:
item: Alarm
print(item) # (3)
- resource: CloudWatchServiceResource
- collection: CloudWatchServiceResource
- item: Alarm