(AWS) Managing Multiple Profiles for AWS CLI
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
- Named profiles (AWS Official Documentation):
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html - AWS CLI Command Reference:
https://docs.aws.amazon.com/cli/latest/reference/configure/list.html - Stackoverflow — How Do I Clear The Credentials In AWS Configure?:
https://stackoverflow.com/questions/46319880/how-do-i-clear-the-credentials-in-aws-configure