mypy-boto3-notificationscontacts Type Stubs

1.42.3 · active · verified Sat Apr 11

mypy-boto3-notificationscontacts provides type annotations for the `boto3` AWS UserNotificationsContacts service. It is part of the `mypy-boto3-builder` project, which frequently releases updates to keep pace with `boto3` and `botocore` releases, ensuring up-to-date and accurate type hints for AWS service clients. The current version is 1.42.3.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` client for the UserNotificationsContacts service and type it using `mypy-boto3-notificationscontacts`. It includes a basic interaction (listing contact channels) and error handling, emphasizing the need for both `boto3` and the type stubs, and proper AWS credentials.

import boto3
from typing import TYPE_CHECKING
import os

# Ensure boto3 is installed: pip install boto3
# Ensure stubs are installed: pip install mypy-boto3-notificationscontacts

if TYPE_CHECKING:
    from mypy_boto3_notificationscontacts.client import NotificationsContactsClient
    from mypy_boto3_notificationscontacts.type_defs import ListContactChannelsResponseTypeDef

def get_notifications_contacts_client() -> "NotificationsContactsClient":
    # Use environment variables for credentials in production
    # Example: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME
    return boto3.client(
        "notifications-contacts",
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )

client = get_notifications_contacts_client()

try:
    # Example: Listing contact channels
    response: ListContactChannelsResponseTypeDef = client.list_contact_channels()
    print("Successfully listed contact channels:")
    for channel in response.get("ContactChannels", []):
        print(f"  - Channel ID: {channel.get('ChannelId')}, Type: {channel.get('ChannelType')}")
except client.exceptions.ClientError as e:
    print(f"Error calling list_contact_channels: {e}")
    if e.response.get('Error', {}).get('Code') == 'AccessDeniedException':
        print("Check your AWS credentials and IAM permissions for NotificationsContacts.")

# Example: Creating a contact (requires specific parameters and permissions)
# try:
#     create_contact_response = client.create_contact(
#         ContactAlias="my-contact",
#         DisplayName="My Contact",
#         Type="PERSONAL", # or 'STANDARD'
#         # 'Plan': {'Stage': [{'StageName': 'Default', 'DurationInMinutes': 5, 'Targets': [...]}]}
#     )
#     print(f"Created contact: {create_contact_response.get('ContactArn')}")
# except client.exceptions.ClientError as e:
#     print(f"Error creating contact: {e}")

view raw JSON →