In this article, I will show you how can you use multiple AWS profiles in a single machine, so that you can easily switch between profiles, which can be really time-saving when you are managing multiple AWS accounts.
Set Up your AWS API credentials here
Linux & Mac
For the first time when you try to setup the AWS CLI on your machine, run the configure command.
This command will configure the API keys and secrets into your AWS CLI. After that, you need to open the file where the credentials are stored.
For Linux and Mac users, the AWS credentials file is located in the following location.
So open that file in edit mode by running this command
sudo vi ~/.aws/credentials
After opening that file you need to add your profiles below the default profile. For example, “AWS configure” command will create a default profile. If you want to set multiple profiles, then just add some additional lines like the example below.
After that, when you want to use a different profile than DEFAULT, then please run the following command.
This command will change the AWS profile in your terminal and you can now use that API keys to make API calls on AWS.
Similar like Linux, for windows you need to run the command “AWS configure” to configure the default API keys.
When you run the “AWS configure” command, you will be prompted to give API keys and Secrets. That will stays as your default profile.
If you want to add additional profiles, then you need to open the credetials files which is located in below position.
So for example, if your windows username is “stefan”, then your credentials path will be something like this
so open the file using your favorite editor, and additional profiles like below.
As you now created multiple profiles in credentials file, please run the following commands to switch between different profiles.
setx AWS_PROFILE rns
That’s it. You have now successfully switched to a different profile rather than your default profile.
Switching to different AWS API keys from your AWS CLI command prompt can be tedious work. But AWS has some alternative option to switch profiles inside a terminal. In this article, I have shown that how easily you can do that without breaking your keyboard 🙂