The AWS CLI provides the ability to use the wide range of Amazon Web Services tools and services straight from the command-line.
However, sometimes it’s useful to be able to login to multiple AWS accounts. Luckily, this is possible by adding an additional profile
to your local configuration and then specifying it when making calls to respective services.
Update your local credentials
Step 1. ~/.aws/credentials
[default]
aws_access_key_id = "<MY_FIRST_AWS_KEY_ID>
aws_secret_access_key = "<MY_FIRST_AWS_SCRET_ACCESS_KEY>"
[andrew]
aws_access_key_id = "<MY_SECOND_AWS_KEY_ID>
aws_secret_access_key = "<MY_SECOND_AWS_SCRET_ACCESS_KEY>"
Fill in your own details for the second grouping, mine is called andrew
.
Update your local config
Step 2.~/.aws/config
[default]
region = "<region>"
output = "<json/text>"
[profile andrew]
region = "<region>"
output = "<json/text>"
Fill in your own details for the second grouping, mine is called andrew
.
Run a test command
Step 3. Run a command
aws sts get-caller-identity --profile andrew
You can find more information about this on the AWS documentation over here: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles