mypy-boto3-globalaccelerator type stubs

1.42.3 · active · verified Sat Apr 11

mypy-boto3-globalaccelerator provides type annotations for the boto3 GlobalAccelerator service. It helps developers leverage static type checking with Mypy for AWS Global Accelerator clients, improving code quality and catching potential errors at development time. The current version is 1.42.3, and new versions are regularly released in sync with boto3 and botocore updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-globalaccelerator` to type-hint a `boto3` GlobalAccelerator client and its method parameters. It defines a function to create a Global Accelerator, using `GlobalAcceleratorClient` for client typing and `CreateAcceleratorRequestTypeDef` for request payload typing. Remember to have `boto3` installed and AWS credentials configured to run actual AWS operations.

import boto3
from mypy_boto3_globalaccelerator.client import GlobalAcceleratorClient
from mypy_boto3_globalaccelerator.type_defs import CreateAcceleratorRequestTypeDef
import os

def create_example_accelerator(name: str) -> str:
    """Creates an AWS Global Accelerator accelerator."""
    # Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
    # The following line uses os.environ.get for illustration, boto3 handles credential lookup implicitly.
    # AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
    # AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', '')

    client: GlobalAcceleratorClient = boto3.client("globalaccelerator", region_name="us-west-2")

    request_payload: CreateAcceleratorRequestTypeDef = {
        "Name": name,
        "IpAddressType": "IPV4",
        "Enabled": True,
        "Tags": [
            {"Key": "Project", "Value": "ChecklistDay"},
            {"Key": "Environment", "Value": "Dev"}
        ],
    }

    try:
        response = client.create_accelerator(**request_payload)
        accelerator_arn = response["AcceleratorArn"]
        print(f"Successfully created accelerator: {accelerator_arn}")
        return accelerator_arn
    except client.exceptions.AcceleratorLimitExceededException as e:
        print(f"Error: Accelerator limit exceeded. {e}")
        return ""
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
        return ""

# Example usage (requires AWS credentials and appropriate permissions)
if __name__ == "__main__":
    # For a real run, ensure your AWS environment is configured.
    # For testing, you might mock boto3 or ensure you have a sandbox AWS account.
    # Skipping actual execution for quickstart to avoid live resource creation.
    # accelerator_arn = create_example_accelerator("MyTestGlobalAccelerator")
    # if accelerator_arn:
    #     print(f"Accelerator created with ARN: {accelerator_arn}")
    print("Quickstart example demonstrates type hinting. To run, uncomment the example usage and configure AWS credentials.")

view raw JSON →