71

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?

bpn
  • 3,082
  • 2
  • 19
  • 22

6 Answers6

151

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]
Kakshil Shah
  • 3,466
  • 1
  • 17
  • 31
bpn
  • 3,082
  • 2
  • 19
  • 22
  • 30
    I wasn't able to edit the profile value in the .elasticbeanstalk/config.yml file. Going to the directory and then running the command with the --profile flag allowed met the profile value to be used. `eb init --profile [profilename]`. I followed the example above and used `eb init --profile eb-cli2`. – Random5000 Aug 04 '15 at 20:01
  • 4
    Yup, just creating a new profile and running ```eb init``` actually *changes it back* to whatever the first/original profile was. The ```--profile``` flag was the key for me. – ericpeters0n Mar 08 '16 at 07:15
  • 1
    If anyone encounters an error "ERROR: NotFoundError - Elastic Beanstalk could not find any platforms. Ensure you have the necessary permissions to access Elastic Beanstalk.", make sure to navigate to IAM > Users on aws dashboard, select your user, and Attach the Policy "AWSElasticBeanstalkFullAccess". Cheers – KBog Jun 15 '16 at 18:49
  • I think the path should be: ~/.aws/config not .yaml https://stackoverflow.com/questions/27514937/aws-eb-cli-3-sets-up-application-for-wrong-account – Kim T Jun 14 '17 at 13:45
  • After I did everything here including @EderYif answer it keeps asking "Do you wish to continue with CodeCommit?" and "Do you want to set up SSH for your instances?" and nothing of responses works :( – mimic Jan 08 '19 at 03:12
  • I couldn't find the file on Windows. it is located on C:\Users\USERNAME\.aws\config [docs](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html) – Adrián Rodriguez Jun 27 '19 at 06:59
  • Thanks, man @Random5000. But I need to write --profile profile-name at the end of each line. Can you specify how to use profile-name as default rather than writing ```--profile profile-name``` at the end of each code? – Deepjyoti De Feb 01 '21 at 17:43
43

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)

Developeder
  • 1,579
  • 18
  • 29
4

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

Joël
  • 1,563
  • 1
  • 18
  • 31
2

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 = ...
Dimitris
  • 13,480
  • 17
  • 74
  • 94
  • My tech lead set me up with AWS IAM user with limited access. After I installed awsebcli, I was able to find my `~/.aws/config`. It loaded my profiles from my other accounts, but I don't seem to have a new `aws_access_key_id` and `aws_secret_access_key` for my IAM user account. Can I generate one or does my Tech lead need to do this? – user3871 May 02 '17 at 17:16
1

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
Dharman
  • 30,962
  • 25
  • 85
  • 135
us_david
  • 4,431
  • 35
  • 29
0

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>
LLai
  • 13,128
  • 3
  • 41
  • 45