How to clone an Amazon EC2 instance between 2 different accounts

So here’s the deal.

(note: this only applies to linux, ebs-backed instances)

Let’s say you’ve built a complex server instance under one account, and now, for whatever reason, you need that server to run under a different account.

Yes, you could go about creating an AMI, and packing that up and sharing it with the other account, but lets say this server has multiple EBS volumes attached, and has a larger data footprint than the 8GB that comes with a standard EBS instance root partition.

Not a problem. Amazon recently provided functionality to share volume snapshots with other accounts, which is an ideal way to transfer server instances between accounts.

Here’s the step by step:

1. For each of the volumes that is included in your system, including the root volume, make a snapshot

2. Update the permissions of each of those snapshots so that they are shared with the other account

3. Logout and login to the other account

4. Make sure you are in the same region as the one where the snapshots were created

5. Set the filter to Private Snapshots; the snapshots you previously shared should now appear

6. Create a volume from each of these, and make sure they are all in the same zone

7. Now, create an EBS-backed instance using the same AMI as was used to create the instance you are trying to transfer (the AMI doesn’t need to be the same if you are using Amazon Linux; again, make sure its in the same zone as the volumes you just created

8. After the instance fully deploys, stop it

9. Detach the default 8GB root volume from the instance. Attach the root volume that you created from the snapshot; attach as /dev/sda1

10. Attach all the other volumes you created from the snapshots, making sure to give them the same device names as on the original instance

11. Start the instance

12. You’re done. To connect, use the same method as on the original instance, rather than how Amazon tells you to connect.

3 thoughts on “How to clone an Amazon EC2 instance between 2 different accounts

  1. Kevin

    I don’t understand step 5- I don’t see any filters that I can set, and there are an infinite number of snapshots.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>