62

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
  • 2,732
  • 2
  • 16
  • 22

4 Answers4

129

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

Jehong Ahn
  • 672
  • 7
  • 20
bpn
  • 2,732
  • 2
  • 16
  • 22
  • 27
    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
39

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,329
  • 16
  • 26
3

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,248
  • 1
  • 15
  • 25
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
  • 12,954
  • 17
  • 71
  • 93
  • 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? – Growler May 02 '17 at 17:16