Skip to main content

Python tool for generating AWS SSO configuration and directory structure

Project description

SSO Config Generator

A Python CLI tool for generating AWS SSO configuration and directory structures.

Overview

SSO Config Generator is a standalone Python tool that simplifies AWS SSO configuration management by:

  1. Generating properly configured AWS CLI config files
  2. Creating directory structures that mirror your AWS Organization
  3. Setting up environment files for easy role switching using direnv

Installation

You can install SSO Config Generator using pip:

pip install sso-config-generator

Prerequisites

  • Python 3.8 or higher
  • AWS CLI v2 configured with:
    • Default region set in ~/.aws/config or via AWS_DEFAULT_REGION environment variable
    • AWS SSO configured via aws configure sso
  • direnv (optional, for automatic profile switching)

AWS Configuration

Before using the tool, ensure you have:

  1. Set your AWS region:

    # Either in ~/.aws/config
    [default]
    region = eu-west-1
    
    # Or via environment variable
    export AWS_DEFAULT_REGION=eu-west-1
    
  2. Configure AWS SSO:

    # Configure SSO
    aws configure sso
    # Follow the prompts to enter:
    # - SSO start URL (e.g., https://your-domain.awsapps.com/start)
    # - SSO Region
    # - SSO registration scopes (accept default)
    
    # Login to SSO to create credentials
    aws sso login
    

Cloud9/CloudX Integration

When running in AWS Cloud9 or CloudX environments, the tool will automatically:

  1. Detect if you're in your home directory with an "environment" subdirectory
  2. Change to the "environment" directory
  3. Skip the SSO name in the directory structure

This ensures seamless operation in AWS-provided development environments.

Troubleshooting

  1. "Error: You must specify a region"

    • Use the --region flag: uvx sso-config-generator --region us-east-1
    • Or set AWS_DEFAULT_REGION environment variable
    • Or configure default region in ~/.aws/config
  2. "Unable to locate credentials"

    • Run aws sso login to refresh your SSO credentials
    • Ensure you've completed AWS SSO configuration with aws configure sso
    • Check if your SSO session has expired (sessions typically last 8 hours)
  3. "SSO session is expired"

    • Run aws sso login to start a new session

Usage

Basic Usage

Simply run:

uvx sso-config-generator

This will:

  • Create/update your AWS CLI config file (~/.aws/config)
  • Generate a directory structure in the current directory + sso-name
  • Create .envrc files in each account directory with AdministratorAccess role
  • Use OU structure for directory organization (cached for performance)

The tool caches OU structure information in the same directory as your AWS config file to improve performance. When the cache exists, it will be used automatically with a notification. To rebuild the cache:

uvx sso-config-generator --rebuild-cache

Command Options

Usage: sso-config-generator [OPTIONS]

Options:
  --create-directories/--no-create-directories  Create a directory for each account (default: True)
  --use-ou-structure/--no-use-ou-structure     Create directories for each OU (default: True)
  --developer-role-name NAME                   Role name to use for .envrc files (default: AdministratorAccess)
  --rebuild-cache                              Force rebuild of OU structure cache
  --sso-name NAME                              Use specified SSO name instead of extracting from SSO start URL
  --create-repos-md                            Create repos.md files in each account directory
  --skip-sso-name                              Do not create a directory for the SSO name (default: False)
  --unified-root PATH                          Directory where account directories are created
                                               (default: current directory)
                                               If current directory is named "environment", SSO name is
                                               automatically skipped
  --region REGION                              AWS region to use (default: eu-west-1)
  --validate                                   Validate current AWS SSO configuration instead of generating
  --help                                       Show this message and exit
  --version                                    Show the version and exit

Examples

  1. Basic config generation (uses defaults):
uvx sso-config-generator
  1. Disable OU structure (flat account directories):
uvx sso-config-generator --no-use-ou-structure
  1. Use different role for .envrc files:
uvx sso-config-generator --developer-role-name ReadOnlyAccess
  1. Use specific AWS region:
uvx sso-config-generator --region us-east-1
  1. Force rebuild of OU cache:
uvx sso-config-generator --rebuild-cache
  1. Specify custom root directory:
uvx sso-config-generator --unified-root ~/aws-environments
  1. Skip creating directories (config file only):
uvx sso-config-generator --no-create-directories
  1. Working in an "environment" directory (automatic behavior):
# If your current directory is named 'environment'
cd environment
uvx sso-config-generator
# This will automatically skip creating the SSO name directory
  1. Validate existing configuration:
uvx sso-config-generator --validate

Development

Setup Development Environment

  1. Clone the repository:
git clone https://github.com/easytocloud/sso-config-generator.git
cd sso-config-generator
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install the package in development mode:
pip install -e .

Common Development Tasks

  • Build the package: pip install build && python -m build
  • Run the tool: uvx sso-config-generator
  • Test changes: ./test_sso_config.sh

Versioning

This project uses semantic-release for automated versioning and package publishing. The version is stored in a single source of truth:

  • src/sso_config_generator/version.py: Contains the __version__ variable
  • __init__.py imports this version
  • pyproject.toml is updated automatically by the GitHub workflow

When a commit is pushed to the main branch, the GitHub workflow:

  1. Determines the next version based on commit messages
  2. Creates a GitHub release and tag
  3. Updates the version in version.py and pyproject.toml
  4. Publishes the package to PyPI

To trigger specific version increments, use the following commit message prefixes:

  • feat: - Minor version increment (e.g., 1.1.0 -> 1.2.0)
  • fix:, docs:, style:, etc. - Patch version increment (e.g., 1.1.0 -> 1.1.1)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sso_config_generator-1.3.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sso_config_generator-1.3.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file sso_config_generator-1.3.0.tar.gz.

File metadata

  • Download URL: sso_config_generator-1.3.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sso_config_generator-1.3.0.tar.gz
Algorithm Hash digest
SHA256 be29bed28bddaf180055cc71a274593198c98649d33cc4ecdc5c5a86b7dbd1ca
MD5 4f7920006490b644e626d983f0c72bc1
BLAKE2b-256 1abf39e21943d6af3ce8fb296bfd4822e47dbf43072d2101aaa1467a1c4c9fe0

See more details on using hashes here.

File details

Details for the file sso_config_generator-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sso_config_generator-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52ee300d176a174a42fa8ba8ec8709504bcab376148df78eb7748f8090f5f50d
MD5 0469b09d701d4fbbc0bd5b6419db2635
BLAKE2b-256 7d9545f32c563acc65a4925263ba4540c957708414de34e26ba6b7b49fdc9fec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page