Home

Awesome

zsh-aws-vault

oh-my-zsh plugin for aws-vault

Installation

oh-my-zsh

This plugin is intended to be used with oh-my-zsh

  1. $ cd ~/.oh-my-zsh/custom/plugins (you may have to create the folder)
  2. $ git clone https://github.com/blimmer/zsh-aws-vault.git
  3. In your .zshrc, add zsh-aws-vault to your oh-my-zsh plugins:
plugins=(
  git
  ruby
  zsh-aws-vault
)

zgen

  1. add zgen load blimmer/zsh-aws-vault to your '!saved/save' block
  2. zgen update

Features

This plugin is pretty simple - it provides:

Aliases

AliasExpression
avaws-vault
aveaws-vault exec
avlaws-vault login
avllaws-vault login -s
avliaws-vault login in sandboxed browser profile
avsaws-vault server
avshaws-vault exec $1 -- zsh
avplist aws config / role ARNs
avreval $(AWS_VAULT= aws-vault export --format=export-env $AWS_VAULT)

avli

Login in Private Browsing Window

This alias is currently only supported in OSX and Linux.

This alias will create a sandboxed browser profile after getting the temporary login URL for your AWS profile. This allows opening multiple profiles simultaneously in different browser profiles. This differs from using incognito mode, which shares the same profile across all incognito windows.

You can specify a specific browser to handle your login URL by setting AWS_VAULT_PL_BROWSER to the bundle name of the browser. By default, it will pick your default URL handler in MacOS. It supports the following browsers:

AWS_VAULT_PL_BROWSER valueBrowser
org.mozilla.firefoxFirefox
org.mozilla.firefoxdevelopereditionFirefox Developer Edition
com.google.chromeChrome
com.microsoft.edgemacEdge
com.microsoft.edgemac.devEdge Developer Edition
com.brave.BrowserBrave
com.vivaldi.browserVivaldi

You can pass arbitrary parameters when launching the browser by setting the optional AWS_VAULT_PL_BROWSER_LAUNCH_OPTS environment variable. For example, if you wanted to start new avli browser windows maximized, you can set AWS_VAULT_PL_BROWSER_LAUNCH_OPTS="--start-maximized". Refer to your browser documentation for possible options.

avsh

Create a shell for a given profile.

For example, place the relevant AWS environment variables for your default profile by running:

avsh default

avr

Refresh your credentials without exiting the existing subshell. Available when using aws-vault 7+.

Prompt Segment

This prompt segment echos out the current aws-vault profile you're logged into. I use this for adding a segment into my custom agnoster theme.

For instance, this code:

prompt_aws_vault() {
  local vault_segment
  vault_segment="`prompt_aws_vault_segment`"
  [[ $vault_segment != '' ]] && prompt_segment cyan black "$vault_segment"
}

Produces this segment in my prompt:

screenshot of agnoster theme with aws-vault segment

The instructions to customize the prompt vary based on the theme you use. In some cases, you'll need to create a copy of the theme file and edit it to include the prompt segment. You can check out my custom agnoster theme to see how I updated the prompt.

Prompt Customization

You can customize the prompt segment behavior by overriding these variables:

Variable NameDefaultDescription
AWS_VAULT_PL_CHARThe character to display when logged into an aws-vault profile
AWS_VAULT_PL_DEFAULT_PROFILEdefaultOnly show the character when logged into this profile, not the profile name

Multi Factor Authentication (MFA)

You can override the default MFA prompt by adding the AWS_VAULT_PL_MFA environment variable.

AWS_VAULT_PL_MFA valueDescriptionExample
inlineEnter your MFA token as an additional argument to the command.avsh default 123456<br>avli default 123456
yubikeyGenerate an MFA token from your Yubikey. See the docs for more information.avsh default<br>avsh default my-yubikey-profile<br>avli default<br>avli default my-yubikey-profile