How to use multiple AWS accounts from the command line?

I have two different applications that I host (well, the second one is about to go up) on Amazon EC2.

How can I work with both accounts on the command line (Mac OS X), but save EC2 keys and certificates separately? Do I need to change environment variables before each ec2- * command?

Will I use an alias and have it in the environment setting in the operating mode? Something like:

alias ec2-describe-examples1 = export EC2_PRIVATE_KEY = / path; EC2-describing-instances

+48
amazon-web-services amazon-ec2
Feb 27 '09 at 2:50
source share
5 answers

You can use the following command parameters instead of EC2_PRIVATE_KEY environment EC2_PRIVATE_KEY (and even EC2_CERT ):

  • -K <private key>
  • -C <certificate>

You can put these internal aliases, for example.

 alias ec2-describe-instances1 ec2-describe-instances -K /path/to/key.pem 
+13
Feb 27 '09 at 3:05
source share

You can work with two accounts by creating two profiles on the aws command line. He will offer you the AWS passkey identifier, the AWS secret passkey, and the desired area so that they are ready.

Examples:

 $ aws configure --profile account1 $ aws configure --profile account2 

Then you can switch between accounts by passing the profile on the team.

 $ aws dynamodb list-tables --profile account1 $ aws s3 ls --profile account2 

Note:

If you name the default profile, it will become the default profile , i.e. when there is no --profile option in the command.




Learn more about the default profile.

If you spend more time using Account1, you can do this by default by setting the AWS_DEFAULT_PROFILE environment variable. When the default environment variable is set, you do not need to specify a profile for each command.

Linux, OS X Example:

 $ export AWS_DEFAULT_PROFILE=account1 $ aws dynamodb list-tables 

Windows example:

 $ set AWS_DEFAULT_PROFILE=account1 $ aws s3 ls 
+126
Dec 12 '15 at 23:06
source share

Maybe he still helps someone. You can install it manually.

1) Install to file

 ~/.aws/credentials 

this is

 [default] aws_access_key_id={{aws_access_key_id}} aws_secret_access_key={{aws_secret_access_key}} [{{profile_name}}] aws_access_key_id={{aws_access_key_id}} aws_secret_access_key={{aws_secret_access_key}} 

2) Install to file

 ~/.aws/config 

this is

 [default] region={{region}} output={{output:"json||text"}} [profile {{profile_name}}] region={{region}} output={{output:"json||text"}} 

3) Test it using AWS command line , and the command and output will be JSON

 aws ec2 describe-instances --profile {{profile_name}} 



Link

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles

+22
Nov 28 '15 at 0:39
source share

New aws utilities now support multiple profiles.

If you configure access using tools, it automatically creates a default value in the ~ / .aws / config file.

Then you can add additional profiles - more information at:

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles

+5
Dec 15 '13 at 13:54
source share

You can write a shell script to set the appropriate environment variable values ​​for each account based on user input. To do this, you do not need to create any aliases and, in addition, tools such as ELB tools, automatic scaling tools on the command line will work under several accounts.

0
Feb 17 '12 at 1:25
source share



All Articles