mypy-boto3-discovery Type Annotations

1.42.3 · active · verified Sat Apr 11

This package provides type annotations for the AWS boto3 client for the ApplicationDiscoveryService service. It ensures static type checking with tools like MyPy, catching potential errors before runtime. As of version 1.42.3, it is actively maintained and released in sync with `botocore` updates, typically multiple times a month.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize a type-hinted `ApplicationDiscoveryServiceClient` and call `describe_agents`. It uses `os.environ.get` for region to make it runnable without hardcoding. Remember to configure AWS credentials and ensure the necessary IAM permissions are granted.

import boto3
from mypy_boto3_discovery.client import ApplicationDiscoveryServiceClient
from mypy_boto3_discovery.type_defs import DescribeAgentsResponseTypeDef, AgentInfoTypeDef
import os

def list_discovery_agents() -> None:
    # Using type hints for the boto3 client
    client: ApplicationDiscoveryServiceClient = boto3.client(
        "discovery",
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )

    try:
        # The response object is type-hinted
        response: DescribeAgentsResponseTypeDef = client.describe_agents()
        agents: list[AgentInfoTypeDef] = response.get("agents", [])

        if agents:
            print("Discovery Agents:")
            for agent in agents:
                print(f"  Agent ID: {agent.get('agentId')}")
                print(f"    Agent Status: {agent.get('agentStatus')}")
                print(f"    Host Name: {agent.get('hostName')}")
                print(f"    Version: {agent.get('version')}")
                print(f"    IP Address: {agent.get('agentIp')}")
        else:
            print("No discovery agents found.")

    except Exception as e:
        print(f"Error describing agents: {e}")

if __name__ == "__main__":
    # Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
    # and that the IAM user/role has permissions for 'discovery:DescribeAgents'.
    list_discovery_agents()

view raw JSON →