Move AWS EC2 Instance to another account
Categories:
How to Migrate an AWS EC2 Instance to Another AWS Account

Learn the comprehensive process of moving an Amazon EC2 instance, including its associated data and configurations, from one AWS account to an entirely different AWS account.
Migrating an Amazon EC2 instance to a different AWS account is a common task for various reasons, such as organizational restructuring, mergers and acquisitions, or separating development and production environments. While AWS doesn't offer a direct 'move' button, the process involves creating an Amazon Machine Image (AMI) of your instance, sharing it with the target account, and then launching a new instance from that AMI. This article will guide you through the steps, ensuring a smooth and secure migration.
Understanding the Migration Process
The core of migrating an EC2 instance revolves around the concept of an Amazon Machine Image (AMI). An AMI is a template that contains a software configuration (operating system, application server, and applications) required to launch an instance. By creating an AMI from your source instance, you essentially capture its state, which can then be used to replicate the instance in another account. This process ensures that your operating system, installed software, and data on the root volume are transferred. However, additional steps are required for data on separate EBS volumes and network configurations.
flowchart TD A[Source AWS Account] --> B(Create AMI from EC2 Instance) B --> C{Share AMI with Target Account} C --> D[Target AWS Account] D --> E(Launch New EC2 Instance from Shared AMI) E --> F[Attach EBS Volumes (if any)] F --> G[Configure Networking & Security Groups] G --> H[Verify Instance & Applications] H --> I[Terminate Original Instance (Optional)]
High-level process for migrating an EC2 instance between AWS accounts.
Prerequisites and Considerations
Before you begin the migration, ensure you have the necessary permissions in both the source and target AWS accounts. You'll need permissions to create AMIs, launch instances, manage EBS volumes, and configure networking. Consider the following points:
- Downtime: Creating an AMI from a running instance might cause a brief I/O freeze. For critical applications, consider stopping the instance before creating the AMI to ensure data consistency.
- Data Consistency: If your instance has multiple attached EBS volumes, ensure data consistency across all volumes before creating the AMI. You might need to unmount volumes or use application-level quiescing.
- IP Addresses: Public and private IP addresses will change. Plan for updating DNS records or any hardcoded IP references.
- IAM Roles: IAM roles attached to the source instance will not be automatically transferred. You will need to create and attach appropriate IAM roles in the target account.
- Security Groups & Key Pairs: These are specific to each account and region. You will need to recreate or configure existing security groups and use a new or existing key pair in the target account.
- Region: This guide assumes migration within the same AWS region. Migrating across regions involves an additional step of copying the AMI to the target region.
Step-by-Step Migration Guide
Follow these detailed steps to successfully migrate your EC2 instance.
1. 1. Prepare the Source EC2 Instance
Log in to the AWS Management Console for your source account. Navigate to EC2, select the instance you wish to migrate. If data consistency is critical, consider stopping the instance. For Linux instances, ensure any sensitive data or configurations that should not be part of the AMI are removed or handled appropriately. For Windows instances, ensure Sysprep is not required, or run it if necessary before creating the AMI.
2. 2. Create an AMI from the Source Instance
With the instance selected, go to Actions
> Image and templates
> Create image
. Provide an Image name
and Image description
. Ensure 'No reboot' is unchecked if you want the instance to reboot during AMI creation (recommended for consistency if not stopped manually). Click Create image
. This process will create an AMI and associated snapshots for all attached EBS volumes.
3. 3. Share the AMI with the Target Account
Once the AMI status is available
(check under AMIs
in the EC2 dashboard), select the newly created AMI. Go to Actions
> Modify image permissions
. Under AWS Accounts
, select Private
and enter the 12-digit AWS account ID of your target account. Click Add permission
and then Save changes
. This makes the AMI accessible to the target account.
4. 4. Share EBS Snapshots (if separate data volumes exist)
If your instance has additional EBS data volumes (not just the root volume included in the AMI), you'll need to share their snapshots separately. Navigate to Snapshots
in the EC2 dashboard. Identify the snapshots associated with your AMI (they will have the AMI ID in their description). For each data volume snapshot, select it, go to Actions
> Modify permissions
, and add the target AWS account ID, similar to sharing the AMI. This allows the target account to create new EBS volumes from these snapshots.
5. 5. Launch a New Instance in the Target Account
Log in to the AWS Management Console for your target account. Navigate to EC2 > AMIs
> Private images
. You should see the shared AMI. Select it and click Launch instance from AMI
. Follow the instance launch wizard, selecting the desired instance type, VPC, subnet, and creating/selecting a new key pair. Configure security groups appropriate for the target environment. If you shared additional EBS snapshots, you will need to create new EBS volumes from those snapshots and attach them to the new instance after it's launched.
6. 6. Attach Additional EBS Volumes (if applicable)
If you had separate data volumes, create new EBS volumes from the shared snapshots in the target account. Once created, attach these volumes to your newly launched EC2 instance. You may need to format and mount them within the operating system, just as you would with any new EBS volume.
7. 7. Configure Networking and Security
Ensure the new instance has the correct security groups, network ACLs, and route table entries for its new environment. Update any DNS records or application configurations that relied on the old instance's IP addresses. If the source instance had an IAM role, create an equivalent role in the target account and attach it to the new instance.
8. 8. Verify the Migrated Instance
Thoroughly test the new instance in the target account. Verify that all applications are running correctly, data is accessible, and network connectivity is as expected. Check logs for any errors. This is a critical step to ensure a successful migration.
9. 9. Terminate the Original Instance (Optional)
Once you are completely satisfied that the new instance in the target account is fully functional and stable, you can terminate the original instance in the source account to avoid incurring unnecessary costs. Remember to also delete the AMI and its associated snapshots from the source account if they are no longer needed.