aws-sso-util

4.33.0 · active · verified Fri Apr 17

aws-sso-util is a Python library and CLI tool that simplifies managing AWS Single Sign-On (SSO) credentials and profiles, abstracting away much of the complexity of the AWS CLI's SSO integration. It provides utilities for logging in, fetching temporary credentials, and configuring profiles. The library is actively maintained with frequent, independent releases for its CLI and programmatic components, with the current version being 4.33.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically fetch temporary AWS credentials using `get_credentials`. It's crucial to have your AWS SSO profile configured (e.g., via `aws-sso-util configure populate`) and an active SSO session (via `aws-sso-util login`) before running this code.

import os
from aws_sso_util import get_credentials

# Configure your AWS SSO profile name, e.g., 'my-sso-profile'
# Ensure your AWS config file (~/.aws/config) has the sso_start_url, sso_region, and sso_account_id configured
profile_name = os.environ.get('AWS_SSO_PROFILE', 'default')

try:
    credentials = get_credentials(profile=profile_name)
    print(f"Successfully fetched temporary credentials for profile '{profile_name}':")
    print(f"  Access Key ID: {credentials['AccessKeyId']}")
    print(f"  Secret Access Key: {credentials['SecretAccessKey']}")
    print(f"  Session Token: {credentials['SessionToken'][:8]}...")
    print(f"  Expiration: {credentials['Expiration']}")
except Exception as e:
    print(f"Error fetching credentials: {e}")
    print("Please ensure you've run 'aws-sso-util login' and configured your profile.")

view raw JSON →