{"id":3079,"library":"mypy-boto3-ec2-instance-connect","title":"mypy-boto3-ec2-instance-connect","description":"mypy-boto3-ec2-instance-connect provides type annotations for the `boto3` EC2InstanceConnect service client. It ensures that your interactions with the AWS SDK for Python are type-safe, allowing tools like MyPy to catch potential errors at development time. This package is part of the `mypy-boto3-builder` ecosystem, currently at version 1.42.3, and is frequently updated to align with `boto3` releases and Python typing improvements.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","aws","type-hints","mypy","ec2-instance-connect","type-stubs"],"install":[{"cmd":"pip install mypy-boto3-ec2-instance-connect","lang":"bash","label":"Install service stubs"},{"cmd":"pip install boto3 mypy","lang":"bash","label":"Install core dependencies"}],"dependencies":[{"reason":"Runtime dependency for the AWS SDK client that these stubs type-check.","package":"boto3","optional":false},{"reason":"Required to perform type-checking; these packages provide the type definitions for it.","package":"mypy","optional":false}],"imports":[{"note":"Client type definitions are typically imported conditionally within a TYPE_CHECKING block to avoid runtime dependencies on stub packages.","symbol":"EC2InstanceConnectClient","correct":"from typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient"},{"note":"Type definitions for service request parameters are imported from the `type_defs` module, usually within a TYPE_CHECKING block.","symbol":"SendSSHPublicKeyRequestRequestTypeDef","correct":"from typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from mypy_boto3_ec2_instance_connect.type_defs import SendSSHPublicKeyRequestRequestTypeDef"},{"note":"Type definitions for service response objects are imported from the `type_defs` module, usually within a TYPE_CHECKING block.","symbol":"SendSSHPublicKeyResponseTypeDef","correct":"from typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from mypy_boto3_ec2_instance_connect.type_defs import SendSSHPublicKeyResponseTypeDef"}],"quickstart":{"code":"import os\nfrom typing import TYPE_CHECKING\nimport boto3\n\n# Conditional import for type checking only\nif TYPE_CHECKING:\n    from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient\n    from mypy_boto3_ec2_instance_connect.type_defs import (\n        SendSSHPublicKeyRequestRequestTypeDef,\n        SendSSHPublicKeyResponseTypeDef\n    )\n\ndef get_ec2_instance_connect_client() -> \"EC2InstanceConnectClient\":\n    \"\"\"\n    Returns a type-hinted EC2InstanceConnect client.\n    This function demonstrates how to obtain a client that mypy can type-check.\n    boto3 client creation will implicitly use AWS credentials from environment variables\n    (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) or configuration files.\n    \"\"\"\n    # Explicitly retrieve AWS region to ensure it's set, for example.\n    aws_region = os.environ.get(\"AWS_REGION\", \"us-east-1\")\n    \n    # The returned client will be typed as EC2InstanceConnectClient by mypy\n    # but at runtime it's a botocore.client.EC2InstanceConnect\n    client: \"EC2InstanceConnectClient\" = boto3.client(\"ec2-instance-connect\", region_name=aws_region)\n    return client\n\nif __name__ == \"__main__\":\n    print(\"Attempting to get an EC2InstanceConnect client...\")\n    try:\n        typed_client = get_ec2_instance_connect_client()\n        print(f\"Successfully obtained client (runtime type: {type(typed_client)}).\")\n        print(\"Note: If AWS credentials are not configured, subsequent API calls will fail.\")\n\n        # Example of a type-checked dictionary for an API call\n        # mypy will validate the structure and types of this dictionary\n        sample_request: \"SendSSHPublicKeyRequestRequestTypeDef\" = {\n            \"InstanceId\": \"i-1234567890abcdef0\", # Placeholder for an actual EC2 instance ID\n            \"InstanceOSUser\": \"ec2-user\",         # Placeholder for the OS user\n            \"SSHPublicKey\": \"ssh-rsa AAAAB3NzaC...\", # Placeholder for a valid public key\n            \"AvailabilityZone\": \"us-east-1a\"    # Placeholder for the instance's AZ\n        }\n        print(f\"\\nExample type-checked request parameters:\\n{sample_request}\")\n\n        # To make an actual API call, uncomment the following.\n        # This will require valid AWS credentials and permissions.\n        # response: SendSSHPublicKeyResponseTypeDef = typed_client.send_ssh_public_key(**sample_request)\n        # print(f\"\\nAPI Response: {response}\")\n\n    except Exception as e:\n        print(f\"Error: Could not initialize client or access AWS: {e}\")\n        print(\"Please ensure boto3 is installed and AWS credentials (e.g., via environment variables like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION or ~/.aws/credentials) are configured correctly.\")","lang":"python","description":"This quickstart demonstrates how to initialize a `boto3` EC2InstanceConnect client and leverage `mypy-boto3-ec2-instance-connect` for type-hinting. The client creation relies on `boto3`'s standard credential chain (e.g., environment variables, `~/.aws/credentials`). Mypy will validate the types of the client object and any request dictionaries at static analysis time, enhancing code reliability."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Starting with `mypy-boto3-builder` version 8.12.0 (which generates this stub package), Python 3.8 is no longer supported. The minimum required Python version is now 3.9.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.12.0, mypy-boto3-ec2-instance-connect >= 1.42.0"},{"fix":"Review and update your code to reflect the new TypeDef names, consulting the specific service's `type_defs.pyi` file if you encounter `NameError` during type checking.","message":"In `mypy-boto3-builder` 8.9.0, there were breaking changes to TypeDef naming conventions. Type definitions for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting TypeDef `Extra` postfixes were moved to the end.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.9.0, mypy-boto3-ec2-instance-connect >= 1.41.x"},{"fix":"Ensure `boto3` is installed in your environment: `pip install boto3`.","message":"This package provides *only* type stubs. It does not include the `boto3` library itself. You must install `boto3` separately for your code to run.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Wrap type-stub imports with `from typing import TYPE_CHECKING` and `if TYPE_CHECKING:`.","message":"The primary utility of `mypy-boto3-ec2-instance-connect` is for static type checking. Imports from this package (e.g., `from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient`) should ideally be placed within an `if TYPE_CHECKING:` block to prevent runtime dependencies and potential import errors if the stub package is not present at runtime.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}