Type Annotations for boto3 NetworkFirewall

1.42.3 · active · verified Sat Apr 11

mypy-boto3-network-firewall provides comprehensive type annotations for the AWS boto3 Network Firewall service (version 1.42.3). These type stubs are generated by mypy-boto3-builder (version 8.12.0) and enhance developer experience in IDEs like VSCode and PyCharm, as well as with static type checkers such as Mypy and Pyright. The library is actively maintained, with updates released in sync with new boto3 versions and improvements to the underlying builder.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` NetworkFirewall client with type annotations and perform a basic operation like listing firewalls. The `TYPE_CHECKING` block ensures type hints are only present during type checking, avoiding runtime dependencies on `mypy-boto3-network-firewall`.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_network_firewall.client import NetworkFirewallClient

def list_network_firewalls():
    # The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are typically picked
    # up from environment variables or AWS config files.
    # Using os.environ.get for example purposes to avoid hardcoding credentials.
    client: NetworkFirewallClient = boto3.client(
        "network-firewall",
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )

    response = client.list_firewalls(
        MaxResults=5 # Limit for demonstration
    )

    print("Found Firewalls:")
    for firewall in response.get("Firewalls", []):
        print(f"  - {firewall.get('FirewallName')} ({firewall.get('FirewallArn')})")

if __name__ == "__main__":
    import os
    # Set dummy AWS credentials for local execution without actual AWS calls
    # For actual execution, ensure valid credentials and region are configured.
    os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'testing')
    os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'testing')
    os.environ['AWS_SESSION_TOKEN'] = os.environ.get('AWS_SESSION_TOKEN', 'testing')

    try:
        list_network_firewalls()
    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →