Creating an EC2 instance with Ruby SDK without ephemeral storage

amazon ec2amazon-web-servicesruby

I use the Ruby AWS-SDK to create EC2 instances like this :

instance = ec2.instances.create({
  :image_id        => WORKER_AMI,
  :instance_type   => instance_type,
  :key_name        => 'cloud',
  :security_groups => 'worker',
  :user_data       => user_data_script,
  :count           => 1,

  :block_device_mappings => [
    {
     :device_name => "/dev/sda1",
     :ebs         => { :volume_size => 50, :delete_on_termination => true }
    }
  ]
})

When doing that, I get a 50 Gb root volume. But I also get a 360G ephemeral disk I don't need. In the AWS console, you can remove it in the wizard when you launch an instance. But how to do it via the SDK ?

Best Answer

http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#run_instances-instance_method

seems to indicate the following should work:-

:block_device_mappings => 
  [ 
    {ebs device},
    {:deviceName => '/dev/sdb', :virtual_name => :ephemeral0, :no_device => ""}
  ]

The code seems to say it doesn't look like it matters what the value of :no_devices is, as long as it's there...

Alternatively, see if you can find an ami which doesn't have those devices in it's default block mapping. To do this see http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-CreateImage.html

 ec2-create-image instance_id --name name -b /dev/sdb=none /dev/sdc=none etc...