Skip to content

Instantly share code, notes, and snippets.

@pbugnion
Last active January 21, 2020 07:46
Show Gist options
  • Save pbugnion/8e0e2b40ef3160b1eadaea2f4b901def to your computer and use it in GitHub Desktop.
Save pbugnion/8e0e2b40ef3160b1eadaea2f4b901def to your computer and use it in GitHub Desktop.
Manage AWS credentials with pass

Managing multiple AWS credentials with pass

These code snippets demonstrate how to build shell functions to manage AWS credentials stored in pass.

See the accompanying blog post for full details on how to use these.

# These functions can go into your `~/.bashrc`.
aws-activate () {
local profile="$1"
if [[ -z "$profile" ]] ; then
echo "Missing argument PROFILE" >&2
echo "Usage: aws-activate PROFILE" >&2
return 1
fi
eval "$(pass aws-profiles/"$profile")"
}
aws-deactivate () {
unset AWS_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
}
# ~/.config/fish/functions/aws-activate.fish
function aws-activate -d 'Activate an AWS profile stored in pass' --argument profile
if test -z $profile
echo "Missing argument PROFILE" >&2
echo "Usage: aws-activate PROFILE" >&2
return 1
end
pass aws-profiles/$profile | source
end
# ~/.config/fish/functions/aws-deactivate.fish
function aws-deactivate -d 'De-activate an AWS profile'
set -e AWS_PROFILE
set -e AWS_ACCESS_KEY_ID
set -e AWS_SECRET_ACCESS_KEY
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment