Skip to content

Instantly share code, notes, and snippets.

@EntropyWorks
Last active May 21, 2018 23:28
Show Gist options
  • Save EntropyWorks/914f9fda280c84e0f548cfa2d67d3641 to your computer and use it in GitHub Desktop.
Save EntropyWorks/914f9fda280c84e0f548cfa2d67d3641 to your computer and use it in GitHub Desktop.
AWS Credential Swap
#!/bin/bash
#
# Do you have multiple AWS profiles?
# Here is how I deal with them.
#
# Make sure you add "${HOME}/.bash_aws_profile" to your .bashrc or .bash_profile so
# all new terminal sessions are updated with your choice.
#
aws-swap_function() {
AWS_DEFAULT_PROFILE="null"
PS3="Your choice: "
while [[ $AWS_DEFAULT_PROFILE == "null" ]]; do
echo "Please enter the number the AWS profile you want"
# shellcheck disable=SC1117
select AWS_DEFAULT_PROFILE in $(grep "^\[profile" ~/.aws/config | awk '{print $2}' | tr -d ']'); do
if [[ $AWS_DEFAULT_PROFILE == "null" ]]; then
echo "Please enter a valid number. Retry."
else
echo "Setting to: $AWS_DEFAULT_PROFILE Paste the next line into your terminal"
echo "source ${HOME}/.bash_aws_profile"
export AWS_DEFAULT_PROFILE="$AWS_DEFAULT_PROFILE"
export AWS_PROFILE="$AWS_DEFAULT_PROFILE"
{
echo "export AWS_DEFAULT_PROFILE=$AWS_DEFAULT_PROFILE"
echo "export AWS_PROFILE=$AWS_DEFAULT_PROFILE"
} >"${HOME}/.bash_aws_profile"
fi
break
done
done
}
aws-swap_function
# Copyright (c) 2017 Yazz Atlas.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by the Disney DTSS Seattle Group. The name of Disney DTSS Seattle Group
# may not be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
[default]
region = us-west-2
[profile default]
region = us-west-2
[profile qa]
region = us-west-2
[profile stage]
region = us-west-2
[profile prod]
region = us-west-2
[default]
aws_access_key_id = AXXXXXXXXXXXXXXXXXXX
aws_secret_access_key = BXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[qa]
aws_access_key_id = AXXXXXXXXXXXXXXXXXXXQA
aws_secret_access_key = BXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXQA
[stage]
aws_access_key_id = AXXXXXXXXXXXXXSTAGE
aws_secret_access_key = BXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSTAGE
[prod]
aws_access_key_id = AXXXXXXXXXXXXXXXPROD
aws_secret_access_key = BXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXPROD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment