bpn
bpn

Reputation: 3232

How to change the AWS account using the Elastic Beanstalk CLI

I deployed an app using elastic beanstalk to my personal AWS account..Now I want to change the AWS credentials so the eb cli knows to deploy to a different account. But it does not ask me for the AWS keys when I type "eb init". Where do I specify this?

Upvotes: 77

Views: 35706

Answers (6)

LLai
LLai

Reputation: 13396

I would agree with the other answers that using an aws profile is the way to go, but another way to accomplish this if you want to run a one off command without creating an aws profile you can do

AWS_ACCESS_KEY_ID=**** AWS_SECRET_ACCESS_KEY=**** eb <command>

Upvotes: -1

bpn
bpn

Reputation: 3232

I had to add a new profile to this file ~/.aws/config. Example of the file with 2 profiles:

[profile eb-cli]
aws_access_key_id = XXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXX

[profile eb-cli2]
aws_access_key_id = XXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXX

Also make sure to update the profile value in your application .elasticbeanstalk/config.yml

To init using the new profile, use:

eb init --profile [profilename]

Upvotes: 160

us_david
us_david

Reputation: 4917

Specify the profiles in ~/.aws/credentials:

[myprofile2] 
aws_access_key_id = ...
aws_secret_access_key = ...  

Like other has indicated. Then use it in eb cli like this:

eb init --profile myprofile2 

Basically append "--profile myprofile2" in all eb commands:

eb deploy --profile myprofile2 
eb open --profile myprofile2

Upvotes: 1

Jo&#235;l
Jo&#235;l

Reputation: 1695

Using export AWS_EB_PROFILE="default" I was able to use my key from my default profile from ~/.aws/credentials.

For more details: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html

Upvotes: 4

Developeder
Developeder

Reputation: 1619

Bpn's answer is correct just add the next step to avoid spending time as I did..

After updating the ~/.aws/config file, just run:

eb init --profile <profilename>

in order to switch between the account.

(in this case profilename = eb-cli2)

Upvotes: 43

Dimitris
Dimitris

Reputation: 13660

The awsebcli tool automatically creates a file named ~/.aws/config and you can see your keys in there under the [profile eb-cli] category. Just change them there.

[profile eb-cli]
aws_access_key_id = ...
aws_secret_access_key = ...

Upvotes: 2

Related Questions