Package: aws-sso-config-builder
AWS SSO Config BuilderTable of ContentsThe GistWhy?InstallationUsageLicenseThe GistThis tool generates AWS CLI configuration blocks for use with AWS IAM Identity Center
(formerly AWS SSO):Named profilesSSO SessionWhy...would someone use this?If they:Have access to a large or shifting set of accounts and roles through AWS SSODon't already have tools in place to generate and maintain their named profilesWant to automatically generate/regenerate templatized blocks without interfering with manually-defined sections...did I publish this?Afterhttps://github.com/99designs/aws-vault/pull/1088got merged, I wanted to update the script I use to update my AWS CLI configCogwasn't on my radar when I started doing this stuff, but is just what I want to maintain the cleaner bits of my frankenconfigI wanted an excuse to tryHatchon something...the focus on aws-vault?From the user experience perspective, the biggest win is that when using my aws-vault profiles, they just work:If I don't have an active SSO session, it pops open a browser to login without me having to manually typeaws sso loginIf my session credentials are missing or expired, aws-vault refreshes them behind the scenes without killing running commandsBut to be fair, a lot of wy I use aws-vault is habit. If you're not already using it, I'm not here to sell it to you.InstallationInto the Active Python Environmentpip install aws-sso-config-builderWith Pipxpipx install aws-sso-config-builderWith Pipx Alongside CogUseful to supportUsage with Cog.pipx install cogapppipx inject cogapp aws-sso-config-builderUsageGenerate AWS CLIsso-sessionandprofileblocks based on the accounts
and roles granted by your AWS SSO login(s).Use as a CLI tool or from Python.CLIQuickstart with Defaultsgenerate-sso-profiles -s my-sso-directory-nameThis will generatesso-sessionandprofileblocksMore OptionsUsage: generate-sso-profiles [OPTIONS]Options:-s, --sso-directories TEXT     SSO directory names, which will be used:- To define "sso-session" config blocks- To build an SSO start URL  [required]-t, --profile-template TEXT    An AWS CLI profile block template with{placeholders} for profile valuesSupported placeholder variables:- profile_name- account_name- account_id- role_name- sso_session...and any other "key" provided in --extra-vars-e, --extra-vars TEXT          Custom variables in the form "key=value" thatcan be referenced with {placeholders} in aprofile template.-r, --regex-replacements TEXT  Regex replacements to perform on generatedprofile names, in the form'pattern,replacement'--help                         Show this message and exit.PythonQuickstart with Defaultsfromaws_sso_config_builder.gen_configimportgenerate_config_blocksprint(generate_config_blocks(sso_directories=["my-sso-directory-name"]))Usage with CogUseCogto dynamically generate or replace specific sections inside an~/.aws/configfile without touching manually-maintained blocks.This invocation specifies:A custom profile template, including:credential_processprofiles for use withaws-vaultadditional settings defined for each profileSome regex replacements to adjust the generated profile nameAdd this Cog block to a new or existing~/.aws/configfile:#[[[cog#importcog#fromaws_sso_config_builder.gen_configimportgenerate_config_blocks##cog.outl(generate_config_blocks(#sso_directories=["home","work"],#profile_template="""#[profile {profile_name}-sso]#sso_session = {sso_session}#sso_account_id = {account_id}#sso_role_name = {role_name}#output = json#region = us-east-2#cli_history = enabled##[profile {profile_name}]#credential_process = {aws_vault_path} exec --json {profile_name}-sso#output = json#region = us-east-2#cli_history = enabled#""",#regex_replacements={#"speckledmonkey":"sm",#"^Customer":"cust",#"Sandbox-":"sbx-"#},#aws_vault_path="/home/aj/go/bin/aws-vault",#))#]]]#[[[end]]]And then run:cog -r ~/.aws/configNote that this depends on having Cog and aws-sso-config-builder installed in the same Python
environment. See alsoInstallation with Pipx Alongside Cogabove.Licenseaws-sso-config-builderis distributed under the terms of theMITlicense.