(AWS) Managing Multiple Profiles for AWS CLI

Kenta Kodashima
2 min readJul 14, 2020

--

Managing multiple profiles for AWS CLI is super easy and it comes in really handy when you have to deal with multiple AWS accounts or IAM user accounts. In this article, I will show you how you can easily use AWS CLI commands using different AWS accounts.

Prerequisites

  • You have AWS CLI installed (installing AWS CLI)
  • You have IAM user(s) created (creating an IAM user)

My Environment

  • macOS Catalina: Version 10.15.4

1. Create a named profile

In order to create a named profile, you can use the following command. Your terminal will ask your AWS Access Key ID, AWS Secret Access Key, Default region name and Default output format, so go to check your IAM user info and take notes as necessary.

aws configure --profile profile_name

When you want to check the list of your profile or edit your profile names, you can check the config file located at ~/.aws/config. Use the following command to open up the config file.

vi ~/.aws/config

The config file should look like the following. The default profile is used when you don’t specify any profile when you use AWS CLI commands.

[default]
region=us-west-2
[profile profile_name1]
region=us-west-2
output=json
[profile profile_name2]
region=us-west-2

If you want to list the configuration data of any profile, you can use the following command.

aws configure list [--profile profile-name]

2. Run AWS CLI commands with the specific profile

In order to run AWS CLI commands with the specific profile, you can use--profile option. The following command is an example to copy DNS records from Route 53 to your local.

aws route53 list-resource-record-sets --hosted-zone-id hosted-zone-id > path-to-output-file --profile profile_name

3. Remove unwanted profiles

If you have some profiles that you want to remove, all you have to do is remove the profile from credentials and config . Run the following commands and remove the unwanted profiles.

vi ~/.aws/credentials
vi ~/.aws/config

That’s everything for this article. Hope you find this helpful.

References

--

--

Kenta Kodashima
Kenta Kodashima

Written by Kenta Kodashima

I'm a Software Engineer based in Vancouver. Personal Interests: Books, Philosophy, Piano, Movies, Music, Studio Ghibli.