DEV Community

Cover image for How to: copy/move AWS EC2 instance from one account to another
Anatolii
Anatolii

Posted on

How to: copy/move AWS EC2 instance from one account to another

Hello. It is my first post and it will be pretty simple.
I am a beginner in AWS Cloud so if the solution does not belong to best practice - you can bit me in the comments)

Situation:
So, there was a situation when my AWS free tier ends in my old account. I have a running instance with web-server on EC2.

Task:
And I needed to move my single AWS EC2 instance in this old account to another, newly created one.

Action:
The steps to do are:

  • Export the EC2 Instance: Export the EC2 instance we want to copy by creating an Amazon Machine Image (AMI) of the instance. An AMI is a template for creating new EC2 instances. We can create an AMI by selecting the instance in the AWS Management Console, right-clicking on it, and choosing the "Create Image" option. Provide a name and description for the AMI.

Image description

  • Share the AMI: After creating the AMI, we need to share it with the destination AWS account (my new acc, in this case). To do this, we go to the EC2 dashboard in the source (old) AWS account, select the AMI we just created, and choose the "Actions" menu. From there, select "Modify Image Permissions" and enter the account ID of the destination AWS account. Save the changes to make the AMI available in the destination account.

Image description

  • _Import the AMI:_Now we need to log in to the AWS Management Console using the destination (new) AWS account credentials. After that, we need to choose the same region as in the source (old) account and navigate to the EC2 dashboard. Then select the "AMIs" option from the sidebar. Here, we should see the shared AMI from the source (old) account. Select the AMI and choose the "Launch" option to launch a new EC2 instance from the AMI.

Image description

  • Configure the New EC2 Instance: The last but not least step is to follow the prompts to configure the new EC2 instance in the destination (new) account. We can choose the instance type, VPC, subnet, security groups, and other settings based on our requirements. Once configured, we can launch the instance. P.S. We can delete AMI and snapshots on both accounts after the instance is launched for saving the costs proposed (of course we need to set up a backup for our data, but it is the other topic).

Result: As a result we moved our EC2 instance from one aws account to another in the same region.

Thank you for reading.

Later I will add a section to this post about how to copy an instance to another region, and how to create a new instance from our AMI in a new account using Terraform.

Feel free to live comments with critics or not.

Top comments (0)