简体   繁体   English

AWS:在 Mac OS 终端中为多个账户配置 AWS 凭据的热点

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

I found way to configure AWS credentials by我找到了配置 AWS 凭据的方法

aws configure

command.命令。 But this is not very comfortable for me since I'm using multiple AWS accounts.但这对我来说不是很舒服,因为我使用多个 AWS 账户。 Is there any way to make it easy to configure AWS credentials and switch between them?有什么方法可以轻松配置 AWS 凭证并在它们之间切换?

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.如果未指定--profile ,它将使用default配置文件。

All configuration information is stored in the ~/.aws/credentials and ~/.aws/config files.所有配置信息都存储在~/.aws/credentials~/.aws/config文件中。

See: Named profiles - AWS Command Line Interface请参阅: 命名配置文件 - AWS 命令行界面

AWS CLI tool, by default, will create a profile called default when you first run the configure option.默认情况下,AWS CLI 工具将在您首次运行配置选项时创建一个名为 default 的配置文件。 The default profile will also be used when you run any AWS CLI tools.当您运行任何 AWS CLI 工具时,也将使用默认配置文件。

Related: How to configure AWS CLI tool相关:如何配置 AWS CLI 工具

You can configure multiple profiles or accounts for AWS CLI.您可以为 AWS CLI 配置多个配置文件或账户。 AWS calls this named profile and you can then switch to any of the profiles or accounts when running the AWS commands. AWS 调用此命名配置文件,然后您可以在运行 AWS 命令时切换到任何配置文件或账户。

Related: How to switch profiles on AWS CLI相关:如何在 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 CLI 创建多个账户的步骤:使用--profile选项和新配置文件的名称运行aws configure

$ aws configure --profile second_user

Enter AWS Access Key ID for the new profile followed by [ENTER].输入新配置文件的 AWS 访问密钥 ID,然后按 [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.或者,当然,您可以通过文本反应器打开~/.aws/credentials并直接对其进行编辑。 After you can just switch between the profiles by the command在您可以通过命令在配置文件之间切换之后

$ aws configure --profile <name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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