How to use multiple AWS Accounts from the command line?

前端 未结 7 1647
故里飘歌
故里飘歌 2020-12-22 16:35

I\'ve got two different apps that I am hosting (well the second one is about to go up) on Amazon EC2.

How can I work with both accounts at the command line (Mac OS X

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 17:06

    You can work with two accounts by creating two profiles on the aws command line. It will prompt you for your AWS Access Key ID, AWS Secret Access Key and desired region, so have them ready.

    Examples:

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

    You can then switch between the accounts by passing the profile on the command.

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

    Note:

    If you name the profile to be default it will become default profile i.e. when no --profile param in the command.


    More on default profile

    If you spend more time using account1, you can make it the default by setting the AWS_DEFAULT_PROFILE environment variable. When the default environment variable is set, you do not need to specify the profile on 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
    

提交回复
热议问题