Type annotations for aiobotocore ECS

3.4.0 · active · verified Fri Apr 17

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `types-aiobotocore-ecs` to get a type-hinted ECS client. It initializes an `aiobotocore` session, creates an ECS client, and then calls `list_clusters` with full type safety, showing how to access the response attributes.

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())

view raw JSON →