Skip to main content

AWS profile utility

Project description

AWS Profile Utility

The awsprofile utility can be used to simplify working with a large number of profiles. This utility reads from ~/.aws/credentials and ~/.aws/awsprofile to list profiles.

Install

pip install xawsprofile

Usage

# list profiles
awsprofile list

# set profile to profile1 and set alias
eval $(awsprofile set profile1 --alias p1)

# list regions
awsprofile list-regions

Bash Completion

This utility includes the following bash completions:

Select Profile

ap (aws profile) - ap {TAB}{TAB} then select a profile, hit {ENTER}

$ ap prof{TAB}{TAB}
profile1     profile2

Select Region

ar (aws region) - ar {TAB}{TAB}, then select a region, hit {ENTER}

$ ar us-{TAB}{TAB}
us-east-1     us-west-1

Setup Bash Completion

# add to your .bash_profile
eval "$(awsprofile completion bash)"

Setup Zsh Completion

autoload -Uz compinit
compinit

# Add this to your ~/.zshrc
eval "$(awsprofile completion zsh)"

Commands

List Profiles

list - list profiles

$ awsprofile list
profile1
profile2

Set Profile

set - set the current profile using exported environment variables

$ eval(awsprofile set profile1)

# set profile and set alias
$ eval(awsprofile set profile1 --alias p1)

Get Profile

get - get the full profile name

$ awsprofile get profile1
company-A-profile1

List Regions

list-regions - list AWS regions

Configure

config - configure awsprofiles

This currently supports cwd to configure the current working directory with a filter.

# filter only profiles-* and remove `profiles-` prefix
awsprofile config cwd --match 'profiles-(.*)`

Console

console - open AWS console using the current/specified profile

awsprofile set profile1
awsprofile console

# or

awsprofile console --profile-name profile1

Locate CWD File

locate-cwd-file - locate the .awsprofile used by traversing up from the current working directory

Customizations

Aliases

To set an alias, update ~/.aws/awsprofile or use awsprofile set ... --alias ... or use ap {profile} {alias}.

eval $(awsprofile set profile1 --alias p1)

ap profile1 p1

Bash Prompt

If you prefer to update your prompt to display the current AWS profile and region as an interactive prompt, you can update your PS1 as follows:

export OLDPS1=$PS1
export PS1='${AWS_PROFILE} (${AWS_DEFAULT_REGION})> '

You can reset your prompt after by either running export PS1=$OLDPS1 to reset the change, or by reloading your shell.

Naming Rules

To simplify the profile names, rules can be applied when awsprofile list is run.

  • global: ~/.aws/awsprofile
  • working directory: {workdir}/.awsprofile (this overrides anything in global, as well as traverse up the directory tree to locate the .awsprofile file)
# 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 = true

Tips

Rules

  • awsprofile config cwd --match 'profiles-(.*) will setup the current working directory to filter only profiles-* as well as strip profiles- from the profile names. This generates a .awsprofile in the current working directory.

  • awsprofile config cwd-rule --name filter1 --match 'some-prefix-(.*)': remove some-prefix- from all profiles

EKS KubeConfig

Add a kubeconfig context using aws eks update-kubeconfig with a name of {PROFILE_ALIAS}/{CLUSTER_NAME}

# add to ~/.zshrc
eval "$(awsprofile completion zsh)"

function akc {
  PROFILE=$1
  CLUSTER_NAME=$2
  FULL_PROFILE=$(awsprofile get $PROFILE)
  aws eks update-kubeconfig --profile $FULL_PROFILE --name $CLUSTER_NAME --alias "$PROFILE/$CLUSTER_NAME"
}

complete -F _awsprofile akc

# usage
akc profile1 eks-cluster-A

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

xawsprofile-0.3.5.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

xawsprofile-0.3.5-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file xawsprofile-0.3.5.tar.gz.

File metadata

  • Download URL: xawsprofile-0.3.5.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.4 Darwin/21.6.0

File hashes

Hashes for xawsprofile-0.3.5.tar.gz
Algorithm Hash digest
SHA256 54eaab804f40d74d25fcb724840a0b376db756073f4e81601de0b28b05478594
MD5 2072a3a27d7884a686fce014144d129d
BLAKE2b-256 deaa65bc7ddeabc42fc6863660abf3dd3c41d129ab4f182e533f3bc34830bc5e

See more details on using hashes here.

File details

Details for the file xawsprofile-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: xawsprofile-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.4 Darwin/21.6.0

File hashes

Hashes for xawsprofile-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f12da5c0db45f1e6486c51e03d8dab651070dbe1fd0331414d7a3e798dfc5be7
MD5 b0c51d147ab4adb57c962482aabf06be
BLAKE2b-256 828ceaf92be66c5d27081d3efbc0b20e3f39918b9e1fd2a368f7268a5184419e

See more details on using hashes here.

Supported by

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