May 26, 2017

Migrate EC2 Instances from one account to another (same region)




There are a lot of cases, which I encounter every now and then and do not find solutions easily and I have to refer to books that are available with me or on the Internet. One such scenario that I faced recently was that I had a development instance (in my aws account) and I had to create an instance for client and install/deploy all required packages/app etc (in his aws account). At that point I was wondering if there is some way to simply transfer the instance to other account (I was using my personal AWS account for development purposes and had to create/configure instance in client’s account).  Being lazy to the core I just didn't wanted to create an instance and do the rework. 

Lot of times I was regretting not asking client to provide infra for development purposes as well. A lot was going through my mind like “Why I didn’t used docker”, “ Why I didn’t note down all configuration steps”, “Should I write Ansible script to make it easier”. While I was thinking all this and searching web at the same time I came across several answers (on stackoverflow) where it was mentioned how snapshots can be used to create new instances etc.

At that point I decided to explore AWS Console a bit more deeply and decided to play around with it while referring to documentation as well and very soon I was able to migrate instance across accounts in same region.

I am sharing steps below in hope of helping others :
Pre-requisite :
-       You should be able to access the support section of destination account (more on this below).

Step 1: Log into source account and go to EC2.
Step 2: Select the instance that you want to migrate.



Step 3: Create an AMI and give it a name or description that its easier to understand. I named my AMI as devmigrate20may17.



Step 4: Click on Create Image and wait for snapshot to appear in Snapshots section in the same region.

Step 5: Select the snapshot and create image from it.


Step 6: Keep all the values as default and give a descriptive name.



Step 7: Once the Image is created, go to AMI section and select the newly created image.  In lower half note “Permissions” tab, click on that.







Step 8: You will notice that AMI’s are by default private. (Most will get excited at this point). Yes , we can edit and make it public.


Step 9: At this point we need account number of destination account, you can find account number in support section in top right corner copy that account number and paste it in the box. There are two options here to make AMI public i.e it will be visible to everybody and to make it visible to the account number we specify. We will go with the second option for obvious reasons.

Step 10: Log into destination account Go to Images -> AMI and select “Private Images” from drop down filter. Here you will see the AMI and from this AMI you can simply launch an instance.

I hope this post help people like me who needed to migrate instance from one account to another.

Do share your feedback and if you think its helpful, please share it with others as well.

No comments: