Creating your first AWS instance using knife-ec2

To install knife-ec2, simply do a –

gem install knife-ec2

Assuming you have setup your Chef account on a hosted chef server. You will have a knife.rb which will look like:

# See for more information on knife configuration options
current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                “mynodename”
client_key               “#{current_dir}/mynodename.pem”
validation_client_name   “myorgname-validator”
validation_key           “#{current_dir}/myorgname-validator.pem”
chef_server_url          “”
cache_type               ‘BasicFile’
cache_options( :path => “#{ENV[‘HOME’]}/.chef/checksums” )
cookbook_path            [“#{current_dir}/../cookbooks”]

Update the knife.rb with your AWS account creds (access key) –

knife[:aws_access_key_id]     = “abcd”
knife[:aws_secret_access_key] = “xyz”

Also add this line to your knife.rb too:

knife[:aws_ssh_key_id] = “ec2keypair-name”

And simply run the command below –

knife ec2 server create -N chef-node-name -I ami-2d088144 -c /path/to/knife.rb –identity-file /path/to/ec2keypair.pem  -VV  –ssh-user ubuntu –bootstrap-protocol ssh



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s