Type annotations for aiobotocore ECS
types-aiobotocore-ecs provides comprehensive type annotations for the `aiobotocore` client for Amazon Elastic Container Service (ECS). It enhances developer experience by enabling static type checking with tools like MyPy, catching potential errors at compile time rather than runtime. This library is part of the `types-aiobotocore` family, which offers stubs for all AWS services, and is frequently updated to align with the latest `aiobotocore` and AWS API changes.
Common errors
-
ModuleNotFoundError: No module named 'types_aiobotocore_ecs'
cause The `types-aiobotocore-ecs` package is not installed in your environment.fixRun `pip install types-aiobotocore-ecs`. -
error: TypedDict "ListClustersResponseTypeDef" has no item "clusterArns"
cause The type stubs for `types-aiobotocore-ecs` are out of sync with the installed `aiobotocore` version, or the AWS API has changed and your stubs are too old.fixEnsure `aiobotocore` and `types-aiobotocore-ecs` are up-to-date and compatible. Try `pip install --upgrade aiobotocore types-aiobotocore-ecs`. -
error: Argument "client" to "some_function" has incompatible type "Any"; expected "ECSClient"
cause You are passing an `aiobotocore` client to a function that expects a type-hinted `ECSClient` from `types-aiobotocore-ecs`, but the client itself hasn't been explicitly type-hinted.fixAfter creating the client, add a type hint: `client = session.create_client(...)`; then `client: ECSClient`. -
TypeError: object is not subscriptable
cause This can occur on older Python versions (pre-3.9) when using type hints like `list[str]` which require `from __future__ import annotations` or `collections.abc` backports.fixEnsure you are running Python 3.9 or newer, as `types-aiobotocore-ecs` requires it. If you need to support older Python, you might need to use `typing.List[str]` explicitly (though this library itself won't support <3.9).
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` 8.12.0, which generates these type stubs. This library (types-aiobotocore-ecs 3.4.0) explicitly requires Python >=3.9.
- breaking TypeDef naming conventions changed significantly in `mypy-boto3-builder` 8.9.0. Explicitly imported TypeDefs (e.g., `CreateDistributionRequestRequestTypeDef` becoming `CreateDistributionRequestTypeDef`) might have different names.
- gotcha `types-aiobotocore-ecs` provides *only* type stubs. You must also install `aiobotocore` (and potentially `aiobotocore[boto3]` or `aioboto3`) for the actual runtime functionality.
- gotcha For correct type checking, the version of `types-aiobotocore-ecs` should ideally match the major/minor version of your installed `aiobotocore` to ensure API compatibility. Mismatches can lead to incorrect type hints or missing attributes.
Install
-
pip install types-aiobotocore-ecs aiobotocore
Imports
- ECSClient
from aiobotocore.client import Client
from types_aiobotocore_ecs import ECSClient
- ListClustersResponseTypeDef
from types_aiobotocore_ecs import ListClustersResponseTypeDef
from types_aiobotocore_ecs.type_defs import ListClustersResponseTypeDef
Quickstart
import asyncio
import aiobotocore.session
from types_aiobotocore_ecs import ECSClient, ListClustersResponseTypeDef
async def main():
session = aiobotocore.session.get_session()
# Replace 'us-east-1' with your desired AWS region
async with session.create_client("ecs", region_name="us-east-1") as client:
client: ECSClient # Type hint the client for MyPy
print("Listing ECS clusters...")
# The response is type-hinted for static analysis
response: ListClustersResponseTypeDef = await client.list_clusters()
cluster_arns = response.get("clusterArns", [])
if cluster_arns:
print(f"Found {len(cluster_arns)} clusters:")
for arn in cluster_arns:
print(f"- {arn}")
else:
print("No ECS clusters found.")
if __name__ == "__main__":
asyncio.run(main())