Creating an EC2 server with volumes from EBS Snapshots

62 views
Skip to first unread message

Bryan Conrad

unread,
Feb 12, 2015, 12:37:37 PM2/12/15
to ruby...@googlegroups.com
Hi, I'm trying to create a server in EC2 with some volumes made from EBS snapshots attached on startup. Basically, the same functionality as when you launch an AMI from the console, and specify snapshots to create the volumes in the AMI from.

Here's what I've tried:

datestring = Date.today.strftime('%Y%m%d')
puts datestring
data
= compute.snapshots.all(description: "db01r1*data*#{datestring}*").first
log
= compute.snapshots.all(description: "db01r1*log*#{datestring}*").first
journal
= compute.snapshots.all(description: "db01r1*journal*#{datestring}*").first


mapping
= [
 
{
   
DeviceName: '/dev/sdf',
   
Ebs: {
     
SnapshotId: data.id
   
},
 
},
 
{
   
DeviceName: '/dev/sdg',
   
Ebs: {
     
SnapshotId: journal.id
   
},
 
},
 
{
   
DeviceName: '/dev/sdh',
   
Ebs: {
     
SnapshotId: log.id
   
}
 
}
]


pp mapping


s
= compute.servers.create image_id: IMAGE_ID, flavor_id: 'm3.medium', description: "dbtest-#{datestring}", block_device_mapping: mapping


Unfortunately, I get back the following:



/Users/bryan/.rvm/gems/ruby-2.1.5/gems/excon-0.42.1/lib/excon/middlewares/expects.rb:6:in `response_call': InvalidRequest => The request received was invalid. (Fog::Compute::AWS::Error)
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/excon-0.42.1/lib/excon/middlewares/response_parser.rb:8:in `response_call'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/excon-0.42.1/lib/excon/connection.rb:365:in `response'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/excon-0.42.1/lib/excon/connection.rb:235:in `request'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-xml-0.1.1/lib/fog/xml/sax_parser_connection.rb:37:in `request'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-xml-0.1.1/lib/fog/xml/connection.rb:7:in `request'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-1.26.0/lib/fog/aws/compute.rb:522:in `_request'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-1.26.0/lib/fog/aws/compute.rb:517:in `request'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-1.26.0/lib/fog/aws/requests/compute/run_instances.rb:139:in `run_instances'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-1.26.0/lib/fog/aws/models/compute/servers.rb:159:in `save_many'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-1.26.0/lib/fog/aws/models/compute/server.rb:201:in `save'
from /Users/bryan/.rvm/gems/ruby-2.1.5/gems/fog-core-1.27.2/lib/fog/core/collection.rb:50:in `create'
from ./dbtest.rb:70:in `<main>'

Any info about why exactly the request is invalid, or corrections to the device mapping (It's hard to find the docs on this, but it looks correct from the AWS docs I found).

Thanks for any help you can provide,
Bryan

Frederick Cheung

unread,
Feb 13, 2015, 4:18:42 AM2/13/15
to ruby...@googlegroups.com, Bryan Conrad



On 13 February 2015 at 04:42:37, Bryan Conrad (bkco...@gmail.com) wrote:


mapping
= [
 
{
   
DeviceName: '/dev/sdf',
   
Ebs: {
     
SnapshotId: data.id
   
},
 
},
 
{
   
DeviceName: '/dev/sdg',
   
Ebs: {
     
SnapshotId: journal.id
   
},
 
},
 
{
   
DeviceName: '/dev/sdh',
   
Ebs: {
     
SnapshotId: log.id
   
}
 
}
]


Maybe worth checking what the request fog generates looks like like, but i think your mapping should look like

mapping = [
  {
    'DeviceName' => '/dev/sdf',
    ‘Ebs.SnapshotId’ => data.id
  },
   ...
]

At least that’s what I use for some of the other apis that take block device mappings

Fred

Reply all
Reply to author
Forward
0 new messages