简体   繁体   中英

AWS: Hot to configure AWS credentials for multiple accounts in Mac OS terminal

I found way to configure AWS credentials by

aws configure

command. But this is not very comfortable for me since I'm using multiple AWS accounts. Is there any way to make it easy to configure AWS credentials and switch between them?

Yes. You can configure multiple profiles .

The easiest way is to use:

aws configure --profile <name>

You can then use it with:

aws s3 ls --profile <name>

If --profile is not specified, it will use the default profile.

All configuration information is stored in the ~/.aws/credentials and ~/.aws/config files.

See: Named profiles - AWS Command Line Interface

AWS CLI tool, by default, will create a profile called default when you first run the configure option. The default profile will also be used when you run any AWS CLI tools.

Related: How to configure AWS CLI tool

You can configure multiple profiles or accounts for AWS CLI. AWS calls this named profile and you can then switch to any of the profiles or accounts when running the AWS commands.

Related: How to switch profiles on AWS CLI

Steps to create multiple accounts for AWS CLI: Run aws configure with the --profile option and a name for the new profile.

$ aws configure --profile second_user

Enter AWS Access Key ID for the new profile followed by [ENTER].

AWS Access Key ID [None]: YOUR_KEY_HERE
Enter AWS Secret Access Key for the new profile followed by [ENTER].
AWS Secret Access Key [None]: YOUR_SECRET_HERE
Enter Default region name for the new profile followed by [ENTER].
Default region name [None]:
Enter Default output format for the new profile followed by [ENTER].
Default output format [None]:

Check configuration file if it's is properly created.

$ cat .aws/credentials
[default]
aws_access_key_id = YOUR_KEY_1_HERE
aws_secret_access_key = YOUR_SECRET_1_HERE
[second_user]
aws_access_key_id = YOUR_KEY_2_HERE
aws_secret_access_key = YOUR_SECRET_2_HERE

You can repeat this process to create as many profiles as you want. Or, of course, you can open ~/.aws/credentials by the text reactor and edit it directly. After you can just switch between the profiles by the command

$ aws configure --profile <name>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM