1

I'm trying to use two different AWS accounts on my computer. One is for my work and the other one is for my personal project.

I made a new Elastic Beanstalk application with eb-cli commands to create a new application for my personal project. When I initially ran eb init, it didn't ask me to input AWS access id. Because of that, it made a new application in my work AWS account because its AWS access key is already stored on my computer.

How can I use two AWS accounts separately so that I can manage my personal and work projects separately on the same computer?

Jay
  • 189
  • 1
  • 2
  • 8

1 Answers1

2

You can have multiple profiles in ~/.aws/credentials that's then used by most AWS command line tools, including eb and aws...

[invalid]
# Prevent 'aws' from running with default creds
region = us-nonsense-1
aws_access_key_id = AKAINVALID1234567890
aws_secret_access_key = InvalidInvalidInvalidInvalidInvalidAccnt

[work]
region = ap-southeast-2
aws_access_key_id = AKIAWORKACCOUNTXYZ12
aws_secret_access_key = Abcdefg....

[personal]
region = ap-southeast-2
aws_access_key_id = AKIAPERSONALACCESS99
aws_secret_access_key = Zxcvbnm....

Then specify the account / profile you want with shell variable AWS_DEFAULT_PROFILE=work or with aws --profile work ....

I guess eb should support some way to specify the profile on the command line too. If not you can always use the shell environment variable AWS_DEFAULT_PROFILE=....

Other options are described in EB CLI Credentials page.

Hope that helps :)

MLu
  • 24,849
  • 5
  • 59
  • 86
  • Since this might affect my company AWS account, I was very afraid of trying on my own. That's exactly what I was looking for. I really appreciate that. :) – Jay Nov 11 '18 at 20:50
  • By the way, is the file name `credentials` required? or can it be something else? I just checked my `.aws` folder and there is a file named `config` which has my company AWS access key. So, I was wondering if I can just put the my personal AWS access key if the file name doesn't matter. – Jay Nov 11 '18 at 20:52
  • 1
    @Jay it can be in `config` but then the syntax is a little different: `[profile work]` instead of just `[work]` when in `credentials` file. – MLu Nov 11 '18 at 20:56
  • I like the idea of an invalid default :) – Tim Nov 12 '18 at 00:44