Skip to content

Instantly share code, notes, and snippets.

@nz
Created March 19, 2012 21:04
Show Gist options
  • Select an option

  • Save nz/2127104 to your computer and use it in GitHub Desktop.

Select an option

Save nz/2127104 to your computer and use it in GitHub Desktop.
Resize an EC2 instance with EBS root
require 'fog'
current_id = 'i-abcdef'
new_flavor = 'm1.large'
ec2 = Fog::Compute.new(provider: 'AWS')
source = ec2.servers.get(current_id)
dest = ec2.servers.create(
# specify the new instance size
flavor_id: new_flavor,
# set other necessary attributes; in this case we'll copy a few from
# the source server
image_id: source.image_id,
security_groups: source.groups,
key_name: source.key_name
)
# once booted, stop the dest and destroy its EBS root
dest.wait_for { ready? }
dest.stop
dest.wait_for { state == "stopped" }
v = dest.volumes.first
v.force_detach
v.destroy
# stop the source and unmount its EBS root
source.stop
source.wait_for { state == "stopped" }
volume = source.volumes.first
volume.force_detach
# attach the EBS root to the destination server and start it
volume.server = dest
dest.start
# verify all is well, then terminate the source server
#source.destroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment