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