(fast beat music)
- Hello, I'm Julius,
a cloud Support Engineer here at AWS office in Cape Town.
Today, I'll show you how to transfer an Amazon EC2 instance
to a different AWS account.
You'll migrate an EC2 image from one AWS account to another,
and then launch a new EC2 instance based on the shared AMI.
Let me walk you through the process.
On these video I'm using a Linux instance,
but the same steps are applicable for a Windows instance.
As you can see,
I'm already logged into the terminal.
First, I will create a simple file to show
that we are dealing with the same AMI in the other account.
We can see the file is here with the content we added.
Now let's switch to the AWS Management Console.
As you can see,
I'm already logged in.
Let's navigate to the EC2 console.
On the EC2 console,
we'll create a custom AMI from the instance
at the source account that will be shared.
Go to your Instances.
Select the instance.
Go to Actions,
Image, Create Image.
Give it a name and the description.
If the instance is in production and can't be rebooted,
you must check the No reboot box.
Note that if this option is used,
the file system integrity can't be guaranteed.
The next step is to make sure
that we are including all the current Amazon EBS volumes
of the existing instance in the AMI.
Unless you don't remove any volumes,
they will all be added to the AMI by default.
Note, that the data is stored instances storage volumes
is not preserved in AMIs,
so it won't be present on the instance storage volume
of the instance that you launch from that AMI.
Finally, when you're done,
choose the Create Image button to generate the AMI.
The instance is now rebooted and a new AMI will be created.
You can check the whole process by going to AMIs,
other images on the same EC2 console.
Depending on the size of your instance,
the new AMI might take several minutes to be available.
When the AMI is available,
select it and go to Actions,
Modify Image Permissions.
On AWS account number,
enter the account number that you want
to share your instance with.
Then choose Add Permission,
check the following box Add create volume
to allow your EBS volumes to be shared to.
And then choose Save.
In order to use the old key pair from the source account,
we need to extract the public key from the key file
and then import it later to the target account.
You can achieve these using these steps.
on a Linux or Mac terminal,
use SSH keygen with these options along with the PEM file.
The output will be sent to a text file.
From this point,
we'll be working only on the target account,
which means the account
that you're sharing your instance with.
To use the old key pair from the previous account,
we need to import the public key that was exported earlier.
We need to go to EC2 console,
then under Network and Security,
choose Key Pairs.
Choose the Import Key Pair button at the top of the page.
Here you can load the key file previously generated
or manually paste the public key block.
Give it any name you want.
Finally, choose Import.
Now, you can launch the EC2 instance.
Note that AMI's are regional resources.
So make sure you are in the same AWS region
where the original AMI was created.
On the same EC2 console, go to AMI's under Images.
Look for the shared AMI on the Private Images option.
When you find it, select it and choose Launch.
This process is very similar
to launching a new EC2 instance.
You can choose a different instance type here, then next.
Customize it according to your VPC preferences,
such as VPC ID,
subnet and availability zone and so on.
Then choose Next.
You can increase the size of the volumes,
otherwise the instance is created with the same size
as the original instance.
In the next page, you can add tags,
then choose Next again,
select the security group that you want to use
for this instance,
otherwise a new one will be created.
Finally, choose Review and Launch to see an overview
of the instance you are about to create.
After you confirm that everything is fine, choose Launch.
Now you have the option to select the key pair
that you want.
Check the acknowledge box
and then choose Launch Instances.
The instances is being launched.
When the instance is running,
we can connect to it and verify that the new instance
is similar to the first instance
from the previous AWS account.
Let's look for the file that I have previously created.
As you can see,
this is the same document.
The same is valid for any script, file or application
that was present in the original instance.
Finally, just follow the same process
to create a custom image from this new instance.
Using these newly generated AMI from now on
is a best practice,
as using this AMI,
we will avoid any complications
if the source account registers the regionally shared AMI.
Thanks for watching and happy cloud computing
from all of us here at the AWS.
(fast beat music)