How I Successfully Migrated My EC2 Instance to Another AWS Account💡

Gerlyn MGerlyn M
5 min read

Migrating an EC2 instance from one AWS account to another might sound like a technical nightmare, but trust me, it’s easier than you think! I recently went through this process, and I’m here to break it down for you in simple steps. Whether you’re a beginner or an experienced AWS user, this guide will help you migrate your EC2 instance smoothly. Let’s dive in!


Step 1: Stop the EC2 Instance 🫸🛑

The first step is to stop the EC2 instance in the source account. Why?

  • Stopping the instance ensures that all data is written to the disk, and no ongoing processes are modifying the filesystem. This guarantees a consistent snapshot.

  • It reduces the risk of corruption or missing data in the AMI (Amazon Machine Image).

How I Did It:

  1. Logged into the source AWS account.

  2. Navigated to the EC2 Dashboard.

  3. Selected the instance I wanted to migrate.

  4. Clicked Instance State > Stop Instance.


Step 2: Create an AMI Image 📸

Once the instance is stopped, the next step is to create an AMI (Amazon Machine Image). An AMI is a template that contains the information required to launch an instance, including the root volume, permissions, and configurations.

💡
Key Tip: While creating the AMI, I made sure to untick the "Reboot" option. This ensures that the instance remains stopped during the AMI creation process, avoiding any unintended changes.

How I Did It:

  1. Selected the stopped instance in the EC2 Dashboard.

  2. Clicked Actions > Image and Templates > Create Image.

  3. Filled in the details:

    • Name: Gave the AMI a meaningful name.

    • Description: Added a brief description for future reference.

    • Unticked the "Reboot" option to ensure the instance stayed stopped.

  4. Clicked Create Image.


Step 3: Wait for the AMI to Become Available⚙️

Creating an AMI can take a few minutes, depending on the size of the instance. Wait for the AMI to reach the "Available" state in the AMIs section of the EC2 Dashboard.


Step 4: Share the AMI with the Destination Account ⏩

Once the AMI is available, the next step is to share it with the destination AWS account. This allows the destination account to access and use the AMI.

How I Did It:

  1. Went to the AMIs section in the EC2 Dashboard.

  2. Selected the AMI I just created.

  3. Clicked Actions > Modify AMI Permissions.

  4. Added the AWS Account ID of the destination account.

  5. Clicked Save Changes.


Step 5: Verify the AMI in the Destination Account ✅

After sharing the AMI, I switched to the destination AWS account to verify that the AMI was successfully shared.

How I Did It:

  1. Logged into the destination AWS account.

  2. Navigated to the AMIs section in the EC2 Dashboard.

  3. Looked for the shared AMI in the Private image section.

Success! The AMI was visible in the destination account, ready to be used.


Step 6: Copy the AMI to the Destination Account ☕

To ensure the AMI is fully available in the destination account, I copied it. This step is especially important if the source and destination accounts are in different AWS regions.

How I Did It:

  1. Selected the shared AMI in the destination account.

  2. Clicked Actions > Copy AMI.

  3. Chose the destination region and provided a name for the copied AMI.

  4. Clicked Copy AMI.


Step 7: Launch the Instance from the AMI 🚀

Finally, it was time to launch the EC2 instance in the destination account using the copied AMI.

How I Did It:

  1. Selected the copied AMI in the AMIs section.

  2. Clicked Actions > Launch Instance.

  3. Configured the instance settings:

    • Instance Type: Chose the appropriate instance type.

    • Network Settings: Selected the VPC, subnet, and security group.

    • Key Pair: Associated a key pair for SSH access.

  4. Clicked Launch Instance.


Step 8: Verify and celebrate! ✅🥳

Once the instance was launched, I logged in to verify that everything was working as expected. I checked:

  • Applications: Were they running correctly?

  • Data: Was all the data intact?

  • Configurations: Were the settings preserved?

Boom! The migration was successful, and the instance was up and running in the destination account.


Pro Tips for a Smooth Migration: 🚀

  1. Test the Process: Before migrating a critical instance, test the process with a non-essential instance to ensure everything works.

  2. Monitor Costs: Keep an eye on data transfer and storage costs during the migration.

  3. Clean Up: After the migration, delete the AMI and snapshots from the source account to avoid unnecessary charges.


Conclusion: 🎃

Migrating an EC2 instance to another AWS account doesn’t have to be complicated. By following these steps stopping the instance, creating an AMI, sharing it, and launching it in the destination account you can ensure a smooth and hassle-free migration.

📌So, what are you waiting for? Start migrating your EC2 instances today and take control of your AWS infrastructure!


📬Found this guide helpful? Share it with your team or leave a comment below if you have any questions. Don’t forget to follow for more AWS tips and tricks!

#ec2 #aws #ec2migration # devops #cloud #getintokube #getintokubeblogs

17
Subscribe to my newsletter

Read articles from Gerlyn M directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Gerlyn M
Gerlyn M

Gerlyn is a DevOps engineer with a strong passion for Kubernetes and automation. He is always eager to learn and continuously strives to enhance his skills, aiming to become an expert in the field. He loves to share his knowledge with the community.