How To use Multiple AWS profile

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.

aws configure

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.

~/.aws/credentials  

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.

export AWS_PROFILE=rns

This command will change the AWS profile in your terminal and you can now use that API keys to make API calls on AWS.

Windows

Similar like Linux, for windows you need to run the command “AWS configure” to configure the default API keys.

AWS configure

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.

%USERPROFILE%\.aws\credentials 

So for example, if your windows username is “stefan”, then your credentials path will be something like this

C:\Users\stefan\.aws\credentials

so open the file using your favorite editor, and additional profiles like below.

aws multiple profile
aws multiple profile

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.

Conclusion

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 🙂

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply