Package: xawsprofile
AWS Profile UtilityTheawsprofileutility can be used to simplify working with a large number of profiles. This utility reads from~/.aws/credentialsand~/.aws/awsprofileto list profiles.InstallpipinstallxawsprofileUsage# list profilesawsprofilelist# set profile to profile1 and set aliaseval$(awsprofilesetprofile1--aliasp1)# list regionsawsprofilelist-regionsBash CompletionThis utility includes the following bash completions:Select Profileap(aws profile) -ap {TAB}{TAB}then select a profile, hit{ENTER}$approf{TAB}{TAB}profile1profile2Select Regionar(aws region) -ar {TAB}{TAB}, then select a region, hit{ENTER}$arus-{TAB}{TAB}us-east-1us-west-1Setup Bash Completion# add to your .bash_profileeval"$(awsprofilecompletionbash)"Setup Zsh Completionautoload-Uzcompinit
compinit# Add this to your ~/.zshrceval"$(awsprofilecompletionzsh)"CommandsList Profileslist- list profiles$awsprofilelist
profile1
profile2Set Profileset- set the current profile using exported environment variables$eval(awsprofilesetprofile1)# set profile and set alias$eval(awsprofilesetprofile1--aliasp1)Get Profileget- get the full profile name$awsprofilegetprofile1
company-A-profile1List Regionslist-regions- list AWS regionsConfigureconfig- configure awsprofilesThis currently supportscwdto configure the current working directory with a filter.# filter only profiles-* and remove `profiles-` prefixawsprofileconfigcwd--match'profiles-(.*)`Consoleconsole- open AWS console using the current/specified profileawsprofilesetprofile1
awsprofileconsole# orawsprofileconsole--profile-nameprofile1Locate CWD Filelocate-cwd-file- locate the.awsprofileused by traversing up from the current working directoryCustomizationsAliasesTo set an alias, update~/.aws/awsprofileor useawsprofile set ... --alias ...or useap {profile} {alias}.eval$(awsprofilesetprofile1--aliasp1)approfile1p1Bash PromptIf you prefer to update your prompt to display the current AWS profile and region as an interactive prompt, you can update yourPS1as follows:exportOLDPS1=$PS1exportPS1='${AWS_PROFILE} (${AWS_DEFAULT_REGION})> 'You can reset your prompt after by either runningexport PS1=$OLDPS1to reset the change, or by reloading your shell.Naming RulesTo simplify the profile names, rules can be applied whenawsprofile listis run.global: ~/.aws/awsprofileworking directory: {workdir}/.awsprofile (this overrides anything in global, as well as traverse up the directory tree to locate the.awsprofilefile)# rename blah-* by removing "blah-" (ex: blah-test would be just test)
[naming cleanup-blah]
match = blah-(.*)
replace = \1

# hide test-*
[naming hide-test]
match = test-(.*)
visible = false

# hide all but test-*
[naming hide-others]
match = test-(.*)
negate = true
visible = false

# only applies to {workdir}/.awsprofile
[naming]
inherit_global = trueTipsRulesawsprofile config cwd --match 'profiles-(.*)will setup the current working directory to filter onlyprofiles-*as well as stripprofiles-from the profile names. This generates a.awsprofilein the current working directory.awsprofile config cwd-rule --name filter1 --match 'some-prefix-(.*)': removesome-prefix-from all profilesEKS KubeConfigAdd a kubeconfig context usingaws eks update-kubeconfigwith a name of{PROFILE_ALIAS}/{CLUSTER_NAME}# add to ~/.zshrceval"$(awsprofilecompletionzsh)"functionakc{PROFILE=$1CLUSTER_NAME=$2FULL_PROFILE=$(awsprofileget$PROFILE)awseksupdate-kubeconfig--profile$FULL_PROFILE--name$CLUSTER_NAME--alias"$PROFILE/$CLUSTER_NAME"}complete-F_awsprofileakc# usageakcprofile1eks-cluster-A