mypy-boto3-elbv2

1.42.3 · active · verified Fri Apr 10

mypy-boto3-elbv2 provides static type annotations for the boto3 ElasticLoadBalancingv2 (ELBv2) service, generated with mypy-boto3-builder 8.12.0. This package enhances developer experience by enabling type checking, autocompletion, and error detection in IDEs for boto3 clients, paginators, waiters, and type definitions related to AWS ELBv2. The current version is 1.42.3, and it follows the boto3 versioning with frequent updates to align with new AWS service features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted ELBv2 client and use it to describe load balancers, leveraging the provided type definitions for improved code quality and IDE support.

import boto3
from mypy_boto3_elbv2.client import ElasticLoadBalancingv2Client
from mypy_boto3_elbv2.type_defs import DescribeLoadBalancersOutputTypeDef

def get_elbv2_client() -> ElasticLoadBalancingv2Client:
    """Returns a typed ELBv2 client."""
    # boto3-stubs provides auto-discovery for Session.client
    # For standalone mypy-boto3-elbv2, explicit typing is recommended.
    client: ElasticLoadBalancingv2Client = boto3.client("elbv2")
    return client

def list_load_balancers():
    client = get_elbv2_client()
    try:
        response: DescribeLoadBalancersOutputTypeDef = client.describe_load_balancers()
        for lb in response.get("LoadBalancers", []):
            print(f"Load Balancer ARN: {lb['LoadBalancerArn']}, Name: {lb['LoadBalancerName']}")
    except client.exceptions.LoadBalancerNotFoundException:
        print("No load balancers found.")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    list_load_balancers()

view raw JSON →