简体   繁体   中英

ERROR chef powershell ec2

I am trying to connect to ec2 (AWS) from my powershell (windows7) I added the following lines to the knife.rb file:

knife[:aws_access_key_id] = ENV['XXXXXX']
knife[:aws_secret_access_key] = ENV['xxxxxxxxxxxxxxxxxxxxxxxxxx']

I run for example

knife ec2 server list --region eu-west-1

but get the following:

knife : ERROR: You did not provide a valid 'AWS Access Key Id' value. At line:1 char:1
ERROR: You did ... Key Id' value.:String) [], RemoteException
ERROR: You did not provide a valid 'AWS Secret Access Key' value.

do I need to upload the knife.rb file to the server after I saved it? (how?) where should I save my pem file and how should I use it in the commands? i tried for example:

knife ec2 server create -I ami-6e7bd919 -N MyEc2Instance -x ec2-user -r "role[webserver]" -i C:\Users\MyName\Documents\openvoip.pem --region eu-west-1

Thanks!

The knife.rb file should have the following and not as described in the question:

knife[:aws_access_key_id] = "XXXXXXXXXXXXXX"
knife[:aws_secret_access_key] = "XXXXXXXXXXXXXXXXXXXX"

I had no such ENV variables, so I set the credentials directly.

To use environment variables you have to put them first in you ~/.bashrc file:

vi  ~/.bashrc
export AWS_ACCESS_KEY_ID=/home/yourname/.ec2/prodaccess
export AWS_SECRET_ACCESS_KEY=/home/yourname/.ec2/prodsecret

Save. then Source .bashrc file:

. ~/.bashrc

Run: env # to see if your new variables are propagated to environment. Then you may run your knife ec2 command

If you plan on sharing your knife.rb, you might want to keep the environment variables and setup as described under 'Many Users, Same Repo' in the docs, https://docs.getchef.com/config_rb_knife.html .

In order to use the ENV vars, use something like below as opposed to the key values that you appear to use:

knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
knife[:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']

Then, when running knife , ensure your local environment variables are set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM