mypy-boto3-sso Type Stubs for AWS SSO Service

1.42.3 · active · verified Sat Apr 11

mypy-boto3-sso provides type annotations for the AWS Single Sign-On (SSO) service client in `boto3`. It enhances development with static type checking for `boto3` resources, clients, and responses, catching potential errors at development time. The current version is 1.42.3, and it follows a frequent release cadence, often aligning with `boto3`/`botocore` updates and `mypy-boto3-builder` releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-sso` to type-hint your AWS SSO client and its method responses. It uses environment variables for sensitive data to make the example runnable without hardcoding credentials. Remember to install `boto3` alongside `mypy-boto3-sso`.

import boto3
import os
from mypy_boto3_sso.client import SSOClient
from mypy_boto3_sso.type_defs import GetRoleCredentialsResponseTypeDef

# Ensure boto3 is installed and configured (e.g., via AWS CLI or env vars)
# You might need to set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
# or use SSO login methods. For this example, we assume SSO token is available.

# Explicitly type the SSO client
sso_client: SSOClient = boto3.client("sso", region_name="us-east-1")

# Replace with your actual SSO details
ROLE_NAME = os.environ.get("SSO_ROLE_NAME", "YourSSORole")
ACCOUNT_ID = os.environ.get("SSO_ACCOUNT_ID", "123456789012")
ACCESS_TOKEN = os.environ.get("SSO_ACCESS_TOKEN", "your_sso_access_token_here") # Typically obtained from AWS CLI sso login

try:
    # Call a method and type hint its response
    response: GetRoleCredentialsResponseTypeDef = sso_client.get_role_credentials(
        roleName=ROLE_NAME,
        accountId=ACCOUNT_ID,
        accessToken=ACCESS_TOKEN
    )

    print(f"Successfully retrieved role credentials for {ROLE_NAME} in account {ACCOUNT_ID}:")
    print(f"  Access Key ID: {response['roleCredentials']['accessKeyId']}")
    # Note: sensitive information like secretKey and sessionToken should be handled securely
    # print(f"  Secret Key: {response['roleCredentials']['secretAccessKey']}")
    # print(f"  Session Token: {response['roleCredentials']['sessionToken']}")
    print(f"  Expiration: {response['roleCredentials']['expirationDate']}")

except sso_client.exceptions.InvalidRequestException as e:
    print(f"Error: Invalid request - {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →