Skip to content

EC2 module

Index > EC2

Auto-generated documentation for EC2 type annotations stubs module mypy-boto3-ec2.

How to install

VSCode extension

Add AWS Boto3 extension to your VSCode and run AWS boto3: Quick Start command.

Click Modify and select boto3 common and EC2.

From PyPI with pip

Install boto3-stubs for EC2 service.

# install with boto3 type annotations
python -m pip install 'boto3-stubs[ec2]'


# Lite version does not provide session.client/resource overloads
# it is more RAM-friendly, but requires explicit type annotations
python -m pip install 'boto3-stubs-lite[ec2]'


# standalone installation
python -m pip install mypy-boto3-ec2

From conda-forge

Installing mypy-boto3-ec2 from the conda-forge channel can be achieved by adding conda-forge to your channels with:

conda config --add channels conda-forge
conda config --set channel_priority strict

Once the conda-forge channel has been enabled, mypy-boto3-ec2 can be installed with:

conda install mypy-boto3-ec2

It is possible to list all of the versions of mypy-boto3-ec2 available on your platform with:

conda search mypy-boto3-ec2 --channel conda-forge

How to uninstall

python -m pip uninstall -y mypy-boto3-ec2

Usage

Code samples can be found in Examples.

EC2Client

Type annotations and code completion for boto3.client("ec2") as EC2Client boto3 documentation

Usage example
from boto3.session import Session

from mypy_boto3_ec2.client import EC2Client

def get_client() -> EC2Client:
    return Session().client("ec2")

Paginators

Type annotations and code completion for paginators from boto3.client("ec2").get_paginator("...").

Usage example
from boto3.session import Session

from mypy_boto3_ec2.paginator import DescribeAddressesAttributePaginator

def get_describe_addresses_attribute_paginator() -> DescribeAddressesAttributePaginator:
    return Session().client("ec2").get_paginator("describe_addresses_attribute"))

Waiters

Type annotations and code completion for waiters from boto3.client("ec2").get_waiter("...").

Usage example
from boto3.session import Session

from mypy_boto3_ec2.waiter import BundleTaskCompleteWaiter

def get_bundle_task_complete_waiter() -> BundleTaskCompleteWaiter:
    return Session().client("ec2").get_waiter("bundle_task_complete")

EC2ServiceResource

Type annotations and code completion for boto3.resource("ec2") as EC2ServiceResource boto3 documentation

Usage example
from boto3.session import Session

from mypy_boto3_ec2.service_resource import EC2ServiceResource

def get_ec2_resource() -> EC2ServiceResource:
    return Session().resource("ec2")

Collections

Type annotations and code completion for collections from boto3.resource("ec2").*.

Usage example
from boto3.session import Session

from mypy_boto3_ec2.service_resource import ServiceResourceClassicAddressesCollection

def get_collection() -> ServiceResourceClassicAddressesCollection:
    return Session().resource("ec2").classic_addresses

Resources

Type annotations and code completion for additional resources from boto3.resource("ec2").*.

Usage example
from boto3.session import Session

from mypy_boto3_ec2.service_resource import ClassicAddress

def get_resource() -> ClassicAddress:
    return Session().resource("ec2").ClassicAddress(...)

Literals

Type annotations for literals used in methods and schemas.

Usage example
from mypy_boto3_ec2.literals import AcceleratorManufacturerType

def get_value() -> AcceleratorManufacturerType:
    return "amazon-web-services"

Typed dictionaries

Type annotations for typed dictionaries used in methods and schema.

Usage example
from mypy_boto3_ec2.type_defs import AcceleratorCountRequestTypeDef

def get_value() -> AcceleratorCountRequestTypeDef:
    return {
        "Min": ...,
    }