AWS CLI Multi Profile Setup For Linux

AWS CLI Multi Profile Setup For Linux

Hey friends! Here is a quick AWS CLI Multi Profile Setup For Linux. 🙂 We are covering version 2 in this tutorial. The first step is to download the CLI for Linux, you can download it here. Now that we have that sorted out and installed, it's time to setup our profile or multiple profiles if you have many AWS accounts. If you need help installing let me know in the comments down below.

Our first step is to configure the AWS client. To finish this step you need to have your Access Key ID, and you Secret Access Key ID.


$ aws configure --profile dev-armando
AWS Access Key ID [None]: Rando$mMeyThatdoesntworkHomer
AWS Secret Access Key [None]: k213983432SuperSecretKeyThatdoesNothing!
Default region name [None]: eu-west-1
Default output format [None]: 

The "aws configure" command starts the configuration process and the first question we have to answer is, "AWS Access Key ID [None]:". If it helps, you can think of the Access Key ID as the username, and the Secret Access Key ID as the password. Paste in your Access Key ID.

The next question, "Default region name [None]:"

This depends on the default region you want to use. If you need a list of available regions, log into your AWS Web Console and on the start page you can click on your current location in the top right corner.

AWS Regions

The best region for me is eu-west-1 so that's what I entered.

The last question, "Default output format [None]:" The default output format is json. You can press Enter here unless you want another format. Click here to see supported formats.


If we are successful we can run our first AWS CLI command! Remember to switch out the name of the profile for the profile you created.

 aws s3 ls --profile dev-armando 

The output should list all the S3 buckets your user should be able to see.

Now let's take a look under the hood and see what's happening. All this wizard did was create a hidden folder, .aws, in your home directory. It also created two files, config and credentials.

 cd ~/.aws 

 ls -ltr 

You should see the credentials and config files.

 cat config 

You will see the [profile] you just created and it's default region. If you cat the credentials file you will see the access key and the secret access key.

Let's create another profile and learn how to switch between the two. 🙂

$ aws configure --profile production-armando
AWS Access Key ID [None]: Rando$mMeyThatdoesntworkHomer
AWS Secret Access Key [None]: k213983432SuperSecretKeyasddsNothing!
Default region name [None]: eu-west-1
Default output format [None]: 

If you cat config and credentials, you should see two profiles now. Try to list your S3 buckets again, remember to use the new profile name you just created.

 aws s3 ls --profile production-armando 

Yeah! Now you should see all the buckets production-armando, or your user is allowed to view.

Wouldn't it be boring if we had to type in the profile name if we are working on the same account for a long time? Yes, it sure would. 😉

We can put our profile name into an environment variable like this.

 export AWS_PROFILE=dev-armando 

Now you can leave out the profile name.

 aws s3 ls 

You can find more information in the AWS documentation here.

That's it for this short tutorial. I hope it helped you out and remember to have fun.

Leave a Reply

Your email address will not be published. Required fields are marked *