Created
March 4, 2018 02:21
-
-
Save brennie/cf26ee386a81bf2f951178a33f45a656 to your computer and use it in GitHub Desktop.
Run a command with AWS credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# awsrun - Run a command with AWS credentials. | |
# | |
# Credentials are read from lastpass using `lastpass-cli`. The key id for your | |
# account (which can be found via `lpass ls` is expected to be in the file | |
# `.lastpass-key-id`. | |
# | |
# Released as CC0 1.0. | |
# Full license available: https://creativecommons.org/publicdomain/zero/1.0/ | |
set -euo pipefail | |
if (( $# == 0 )); then | |
cat <<-END | |
awsrun: Run a command with AWS credentials. | |
Usage: | |
${0} COMMAND | |
END | |
exit 1 | |
fi | |
# Default to regular pinentry if we don't have this defined. | |
LPASS_PINENTRY="${LPASS_PINENTRY:-$(which pinentry)}" | |
read LASTPASS_KEY_ID < .lastpass-key-id | |
read -r AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY < <( | |
lpass show --all "${LASTPASS_KEY_ID}" | awk ' | |
/Username|Password/ { printf "%s ", $2 } | |
END { printf "\n" } | |
') | |
export AWS_ACCESS_KEY_ID | |
export AWS_SECRET_ACCESS_KEY | |
exec "$@" | |
~/W/p/infrastructure (maste |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment