How to configure knife and EC2 to create a new instance from the command line?
I'm assuming that you are receiving this error while creating a new node and not when you try to set the security credentials in your knife.rb.
To be precise, the error should come up when you initiate:
knife ec2 server create -I <ami-id>
The error
ERROR: You did not provide a valid 'AWS SSH Key Id' value.
is due to a missing SSH Keypair in your knife ec2 server create
command. You need to specify an SSH Keypair whenever you launch an Amazon EC2 instance. This SSH public key is added to a newly launched instance to enable a passwordless SSH login. Keypairs can either be created or imported. Keypairs (for US-East region) can be found at EC2 -> Keypairs section of your Amazon AWS console.
Once you pick an SSH Keypair, you could specify it's name in your knife ec2 create
command as:
knife ec2 server create -I <ami-id> -S <your-ssh-keypair-name>
Note: This will launch an EC2 instance out of the specified ami-id and with the SSH keypair. Knife will proceed towards knife bootstrap
once the instance is launched. To do so, you need to make sure the SSH keypair's private key is added to your ssh-agent session before initiating a knife ec2 server create
. You might also want to specify your Chef server URL with --server-url
option of knife ec2 server create
.
If you want to store the settings in the knife.rb file:
knife[:aws_ssh_key_id] = 'pemfilename'
pemfilename should be the pem file name without the .pem extension and it has to be located in: ~/.ssh/ Also, it has to be chmodded 600: (chmod 600 ~/.ssh/pemfile.pem)
So if your pem file is ~/.ssh/mypem.pem you need to set:
knife[:aws_ssh_key_id] = 'mypem'
Then the access key and the secret accees keys:
knife[:aws_access_key_id] = 'AAAAAAAAAAAAAAAAAAAA'
knife[:aws_secret_access_key] = 'UYUYW/IUYITYUIGGUGIUYGKJHGHG'
After you save the file, you can run:
knife ec2 server create --node-name mynodename.mydomain.com --run-list "role[myrole]"
As rhetonik mentioned above - you need to specify keypair name to be used for a new server.
One option is to pass it directly using -S switch to knife ec2
command,
the other option is to add something like that to your knife.rb
configuration file:
knife[:aws_ssh_key_id] = "myawshosts"