Dear Readers,
In this article,we will see Transfer EC2 Instance to another AWS Account.
Implementation Steps
- Launch Linux EC2 Instance.
- Connect to Linux EC2 Instance through putty and Install updates,package “tree” and create files,directories.
- Create AMI (Amazon Machine Image).
- Copy AMI to another AWS Account.
- Launch Linux EC2 instance from AMI.
- Connect to Linux EC2 Instance through putty and verify files.
First, we need to AWS Console page by using below link.
https://aws.amazon.com/console/
Click on sign in to Console button.
Logging to aws account
Login using username & password and click on sign in.
Enter to AWS Management Console
We can see the AWS Management Console Dashboard.
Go to Services, under the compute module click EC2 service to open.
1. Launch Linux EC2 Instance
Please check below link to Launch Linux Server.
Launch Linux Launch Linux Server
We can see Linux Server “My Linux” which was created earlier.
2. Connect to Linux Server through putty and Install updates,package “tree” and create files,directories.
Open Linux Server terminal,.
Open Linux Terminal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Using username "ec2-user". Authenticating with public key "imported-openssh-key" Last login: Sat Nov 23 19:50:40 2019 from 124.123.103.5 __| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___| https://aws.amazon.com/amazon-linux-2/ 5 package(s) needed for security, out of 13 available Run "sudo yum update" to apply all updates. [ec2-user@ip-172-31-0-157 ~]$ |
Switch to root user
1 2 3 4 |
[ec2-user@ip-172-31-0-157 ~]$ sudo su [root@ip-172-31-0-157 ec2-user]# |
Install Updates
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
[root@ip-172-31-0-157 ec2-user]# yum update -y Loaded plugins: extras_suggestions, langpacks, priorities, update-motd amzn2-core | 2.4 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package file.x86_64 0:5.11-33.amzn2.0.2 will be updated ---> Package file.x86_64 0:5.11-35.amzn2.0.1 will be an update ---> Package file-libs.x86_64 0:5.11-33.amzn2.0.2 will be updated ---> Package file-libs.x86_64 0:5.11-35.amzn2.0.1 will be an update ---> Package kernel.x86_64 0:4.14.154-128.181.amzn2 will be installed ---> Package python.x86_64 0:2.7.16-3.amzn2.0.1 will be updated ---> Package yum.noarch 0:3.4.3-158.amzn2.0.3 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================================ Package Arch Version Repository Size ================================================================================================ Installing: kernel x86_64 4.14.154-128.181.amzn2 amzn2-core 20 M python2-rpm x86_64 4.11.3-40.amzn2.0.3 amzn2-core 84 k replacing rpm-python.x86_64 4.11.3-25.amzn2.0.3 Updating: file x86_64 5.11-35.amzn2.0.1 amzn2-core 57 k file-libs x86_64 5.11-35.amzn2.0.1 amzn2-core 339 k python x86_64 2.7.16-4.amzn2 amzn2-core 92 k yum noarch 3.4.3-158.amzn2.0.3 amzn2-core 1.2 M Cleanup : yum-3.4.3-158.amzn2.0.2.noarch 15/25 Erasing : rpm-python-4.11.3-25.amzn2.0.3.x86_64 16/25 Cleanup : python-libs-2.7.16-3.amzn2.0.1.x86_64 24/25 Verifying : python-2.7.16-4.amzn2.x86_64 3/25 Verifying : yum-3.4.3-158.amzn2.0.3.noarch 4/25 Verifying : rpm-libs-4.11.3-40.amzn2.0.3.x86_64 5/25 Verifying : rpm-build-libs-4.11.3-40.amzn2.0.3.x86_64 6/25 Verifying : kernel-4.14.154-128.181.amzn2.x86_64 7/25 Verifying : rpm-4.11.3-40.amzn2.0.3.x86_64 8/25 Verifying : file-libs-5.11-35.amzn2.0.1.x86_64 9/25 Verifying : rsyslog-8.24.0-41.amzn2.2.1.x86_64 10/25 Verifying : rpm-plugin-systemd-inhibit-4.11.3-40.amzn2.0.3.x86_64 11/25 Verifying : python-devel-2.7.16-4.amzn2.x86_64 12/25 Verifying : python2-rpm-4.11.3-40.amzn2.0.3.x86_64 13/25 Verifying : python-devel-2.7.16-3.amzn2.0.1.x86_64 14/25 Verifying : rpm-build-libs-4.11.3-25.amzn2.0.3.x86_64 20/25 Installed: kernel.x86_64 0:4.14.154-128.181.amzn2 python2-rpm.x86_64 0:4.11.3-40.amzn2.0.3 Updated: file.x86_64 0:5.11-35.amzn2.0.1 file-libs.x86_64 0:5.11-35.amzn2.0.1 python.x86_64 0:2.7.16-4.amzn2 python-devel.x86_64 0:2.7.16-4.amzn2 python-libs.x86_64 0:2.7.16-4.amzn2 rpm.x86_64 0:4.11.3-40.amzn2.0.3 rpm-build-libs.x86_64 0:4.11.3-40.amzn2.0.3 rpm-libs.x86_64 0:4.11.3-40.amzn2.0.3 rpm-plugin-systemd-inhibit.x86_64 0:4.11.3-40.amzn2.0.3 rsyslog.x86_64 0:8.24.0-41.amzn2.2.1 yum.noarch 0:3.4.3-158.amzn2.0.3 Replaced: rpm-python.x86_64 0:4.11.3-25.amzn2.0.3 Complete! [root@ip-172-31-0-157 ec2-user]# |
Verify files in the current directory
1 2 |
[root@ip-172-31-0-157 ec2-user]# ls |
Check the tree package installed or not
1 2 3 4 |
[root@ip-172-31-0-157 ec2-user]# rpm -q tree package tree is not installed |
Make Directory “ktexperts”
1 2 3 4 5 6 |
[root@ip-172-31-0-157 ec2-user]# mkdir ktexperts [root@ip-172-31-0-157 ec2-user]# ls Ktexperts |
Go inside Directory “ktexperts” and make a file “aws” then put some content
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@ip-172-31-0-157 ec2-user]# cd ktexperts/ [root@ip-172-31-0-157 ktexperts]# vi aws [root@ip-172-31-0-157 ktexperts]# cat aws ktexperts is a knowledge sharing platform It will help you to get knowledge on updated technologies. [root@ip-172-31-0-157 ktexperts]# [root@ip-172-31-0-157 ktexperts]# tree bash: tree: command not found [root@ip-172-31-0-157 ktexperts]# |
Install the package “tree”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
[root@ip-172-31-0-157 ktexperts]# cd /home/ec2-user/ [root@ip-172-31-0-157 ec2-user]# yum install tree -y Loaded plugins: extras_suggestions, langpacks, priorities, update-motd amzn2-core | 2.4 kB 00:00:00 Resolving Dependencies Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: tree x86_64 1.6.0-10.amzn2.0.1 amzn2-core 47 k Transaction Summary ================================================================================ Install 1 Package Total download size: 47 k Installed size: 83 k Downloading packages: tree-1.6.0-10.amzn2.0.1.x86_64.rpm | 47 kB 00:00:00 Running transaction check Installing : tree-1.6.0-10.amzn2.0.1.x86_64 1/1 Verifying : tree-1.6.0-10.amzn2.0.1.x86_64 1/1 Installed: tree.x86_64 0:1.6.0-10.amzn2.0.1 Complete! [root@ip-172-31-0-157 ec2-user]# |
Check the tree package installed or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@ip-172-31-0-157 ec2-user]# rpm -q tree package tree is installed. [root@ip-172-31-0-157 ec2-user]# tree .└── ktexperts └── aws 1 directory, 1 file [root@ip-172-31-0-157 ec2-user]# |
In this Server, we can see one directory “ktexperts” ,one file “aws”.
One package has been installed i.e,tree.
3. Create AMI (Amazon Machine Image)
Select your instance “My Linux”
Go to actions, click on Create Image under the Image.
Specify Name of the Image “Ktexperts – AMI (Mumbai) and click on Create Image.
One success message will be displayed. Click ‘Close’.
and click on Close.
View your AMI
Navigate to AMIs under IMAGES.
we can see the AMI “Ktexperts – AMI (Mumbai) has been created.
Note
When you create Image , Snapshot will also be created automatically.
Go Snapshots, we can see one snapshot created by Created by Create Image.
View your Snapshot
Navigate to Snapshots under Elastic Block Storage.
We can see the created snapshot as shown below.
Note
If you want to copy image to another account, you need to know another AWS Account ID then only we can copy to that account.
4. Copy Account ID of Another AWS Account
Logging to aws account
Provide username and password then click on sign in.
Click on My Account .
Copy Account Id in the Account Settings.
Copy AMI to Another AWS Account
Select you AMI,click on Modify Image Permissions in the Actions.
Select Private and paste Account id which was copied from Another AWS Account then click on Add Permission.
The account id has been added successfully.
Select Create Volume Permissions and click on Save.
Verify AMI in another AWS Account
Go to AMIs and select private Images then only it will show the private images.
We can see the AMI has been copied to another AWS Account successfully.
Note
When you create Image , Snapshot will also be created automatically.
Go Snapshots, we can see one snapshot created by Created by Create Image.
View your Snapshot
Navigate to Snapshots under Elastic Block Storage.
We can see the created snapshot as shown below.
5. Launch Linux Instance From AMI
Select AMI and click on Launch.
Choose an Instance type
Choose the Type of instance depending on your requirements.
Instance types comprise of varying combinations of CPU, memory, storage, and networking capacity.
select the default option of t2. micro – this instance type is covered within the free tier. Then click on Configure Instance Details
Configure Instance Details
Configure EC2 instance details as per requirements of your environment and click on Add Storage.
Add Storage
Give size 50 GB for root volume.
Click on Add Tags.
Add Storage
Click on Add Tags.
Provide the name for the Linux virtual machine for easier understanding and click on Configure Security Groups.
Configure Security Group
A security group allows configuring firewall rules to allow traffic as needed. Only one rule has been added to allow remote connection.
SSH Is enough to connect to our Linux virtual server and click on Review and Launch
Review Instance Launch
Review and confirm the configuration of the instance. Click on the Edit button on each configuration item to make changes and click on Launch.
Choose Existing Key Pair and Launch Your Instance
Choose existing key pair and name it My Linux. Then click Download Key Pair.
After you have downloaded and saved your key pair, click Launch Instance to start your Linux instance.
Click on View Instances to view the instance you have just created and see its status.
We can see Linux Server “My Linux – AMI (First Account – Mumbai)” which was created earlier.
6. Connect to Linux Instance through putty and Verify files
Copy Public DNS of your instance.
Enter public DNS in putty and upload PPK file then terminal will be opened.
It will ask username, specify “ec2-user” .
Open Linux Terminal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Using username "ec2-user". Authenticating with public key "imported-openssh-key" Last login: Sat Nov 23 19:50:40 2019 from 124.123.103.5 __| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___| https://aws.amazon.com/amazon-linux-2/ 5 package(s) needed for security, out of 13 available Run "sudo yum update" to apply all updates. [ec2-user@ip-172-31-0-157 ~]$ |
Switch to root user
1 2 3 4 |
[ec2-user@ip-172-31-0-157 ~]$ sudo su [root@ip-172-31-0-157 ec2-user]# |
Verify files in current directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
root@ip-172-31-43-140 ec2-user]# ls ktexperts [root@ip-172-31-43-140 ec2-user]# tree . └── ktexperts └── aws 1 directory, 1 file [root@ip-172-31-43-140 ec2-user]# |
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates
KTEXPERTS is always active on below social media platforms.
Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform