mypy-boto3-organizations - Type annotations for AWS Organizations

1.42.83 · active · verified Sat Apr 11

mypy-boto3-organizations provides type annotations for the `boto3` AWS SDK's Organizations service. It enhances static type checking with tools like `mypy` and `pyright`, offering improved code quality and IDE support. This package, currently at version 1.42.83, is automatically generated by `mypy-boto3-builder` and frequently updated to maintain compatibility with `boto3` releases.

Warnings

Install

Imports

Quickstart

Demonstrates how to use `mypy-boto3-organizations` to type-hint a `boto3` Organizations client and its method calls, including request and response `TypeDef` objects. This allows static analysis tools to validate your AWS API interactions.

import boto3
from mypy_boto3_organizations import OrganizationsClient
from mypy_boto3_organizations.type_defs import CreateAccountRequestTypeDef, CreateAccountResponseTypeDef


def create_aws_account(account_name: str, email: str, role_name: str) -> CreateAccountResponseTypeDef:
    """Creates a new AWS account within an organization."""
    client: OrganizationsClient = boto3.client("organizations")
    
    request: CreateAccountRequestTypeDef = {
        "Email": email,
        "AccountName": account_name,
        "RoleName": role_name,
        "Tags": [
            {"Key": "Project", "Value": "MyProject"}
        ]
    }
    
    response: CreateAccountResponseTypeDef = client.create_account(**request)
    print(f"Account creation requested: {response['CreateAccountStatus']['State']}")
    print(f"Account ID: {response['CreateAccountStatus'].get('AccountId', 'N/A')}")
    return response

# Example usage (requires AWS credentials configured for Organizations service)
if __name__ == "__main__":
    # In a real scenario, use unique values and ensure email is valid
    # and not already associated with an AWS account.
    # Replace with actual email and account name for testing.
    test_account_name = "MyTestOrgAccount"
    test_email = "test-account-owner@example.com" # Use a real, unique email
    test_role_name = "OrganizationAccountAccessRole"
    
    try:
        # This call will actually attempt to create an account in your AWS Organizations.
        # Be cautious when running this in a production environment.
        # For demonstration purposes, we'll comment out the actual call.
        # response = create_aws_account(test_account_name, test_email, test_role_name)
        print("To run, uncomment the create_aws_account call with valid parameters.")
    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →