简体   繁体   中英

attach ebs on ec2 instance create

I am trying to create and attach an EBS volume on instance creation but I am getting error of no option :ebs , I am able to do this from AWS console so there should be some way with which I can create instance using a volume as disk

instance = ec2.instances.create(:image_id => ami-aa***,
  :key_name => ec2.key_pairs["Dev-node"].name,
  :ebs => {
    :volume_size => 20, #size in GBs
    :delete_on_termination => true
  },
  :instance_type => 't1.micro')

I believe you need to pass the :block_device_mapping key, which should be an Array of hashes as outlined here , eg:

instance = ec2.instances.create(
  :image_id => "ami-aa***",
  :key_name => ec2.key_pairs["Dev-node"].name,
  :block_device_mapping => [
    {
      "DeviceName" => "/dev/sdf",
      "Ebs.VolumeSize" => 20,
      "Ebs.DeleteOnTermination" => true
    }
  ],
  :instance_type => 't1.micro'
)

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