2

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 ?

aurels
  • 273
  • 2
  • 6

1 Answers1

3

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...
Decado
  • 1,949
  • 11
  • 17
  • Thanks. This strange param should do the trick, I'll try and update this page. – aurels Sep 26 '13 at 14:41
  • For your other suggestion, I use a custom AMI of mine. Do you know if it's possible to remove the device from it easily ? Creating an instance from the AMI in the console, removing the device in the wizard, and then creating a new AMI from the resulting instance should work, right ? – aurels Sep 26 '13 at 14:43
  • Answer updated to include block-devive-mapping override for create image. – Decado Sep 27 '13 at 08:01
  • Can't make it work : { :device_name => '/dev/xvdb', :virtual_name => 'ephemeral0', :no_device => '' } – aurels Sep 27 '13 at 09:15
  • If you pass something to :no_device it raises an error. – aurels Sep 27 '13 at 09:15
  • I could do what I wanted by generating a new AMI without ephemeral. For the Ruby client, I asked here : https://github.com/aws/aws-sdk-ruby/issues/210 I'll update the answers if I get responded. – aurels Sep 27 '13 at 09:48