Wednesday, January 16, 2013

Migrate EC2 to a different Availability Zone

I setup some EC2 instances in a VPC. They defaulted to the us-east-1d availability zone. Once I had everything configured and wanted to switch from on-demand to reserved instances, I was shocked to discover that no "Linux/UNIX (Amazon VPC)" micro instnaces were available in us-east-1d. Plenty were available in us-east-1b.

It's not very painful to migrate an instance to a new region, but because I'm inside a VPC and I want to keep the internal IP of my machines I must delete the old subnet and create a new subnet in the new availability zone. Now for the big gulp: that means I must first terminate (i.e. nuke) all the instances currently in that subnet. It will work but be careful to do things in the right order.

AWS > EC2 > Instances
 > yourBox > Actions > Stop > Yes, Stop
 > yourBox > Actions > Create Image (EBS AMI)
  Image Name: yourImage
  (everything else default)
  > Yes, Create > Close

Repeat for all instances in your subnet. Wait for the process to complete, you can view the results from the AMIs and Snapshots sidebar links.

AWS > EC2 > Instances
 > yourBox > Actions > Change Termination Protection > Yes, Disable
 > yourBox > Actions > Terminate > Yes, Terminate

VPC > Subnets
 > yourSubnet > Delete > Yes, Delete
 > Create Subnet
  VPC: yourVPC
  Availability Zone: us-east-1b
  CIDR Block:
  > Yes, Create
 > yourSubnet > Route Table > replace > Yes, Replace
 // this switches from the default (empty) route table to your 
 // route table that contains your internet gateway

AWS > EC2 > AMIs > yourImage > Launch
 Number of Instances: 1
 Instance Type: t1.micro // based on the original
 Launch Instances: VPC: Subnet: yourNewSubnet
 // this took a while to update, I closed and re-opened the browser
 > Continue
  Termination Protection: [checked]
  eth0: IP Address: sameAsBefore
 > Continue > Continue > Name: sameAsBefore
 > Continue > Choose from your existing Key Pairs: sameAsBefore 
 > Continue > Choose one or moore of yoru existing Security Groups: sameAsBefore
 > Continue > Launch > Close

VPC > Elastic IPs > sameAsBefore > Associate Address > yourInstance > Yes, Associate

Repeat for all instances in your subnet. WARNING: this will change underlying values like MAC address so any machine-bound passwords will need to be re-bound.

{ "loggedin": false, "owner": false, "avatar": "", "render": "nothing", "trackingID": "UA-36983794-1", "description": "", "page": { "blogIds": [ 390 ] }, "domain": "", "base": "\/michael", "url": "https:\/\/\/michael\/", "frameworkFiles": "https:\/\/\/michael\/_framework\/_files.4\/", "commonFiles": "https:\/\/\/michael\/_common\/_files.3\/", "mediaFiles": "https:\/\/\/michael\/media\/_files.3\/", "tmdbUrl": "http:\/\/\/", "tmdbPoster": "http:\/\/\/t\/p\/w342" }