Published on: June 1, 2021 by Mrudhul Mohan
Scenario:
Method 1
By creating an AMI
Create a New EC2 instance with a New key pair named “Webserver-private-key”
Download the private key and share it with the client. Please note that Amazon will not save the copy of the private key.
Scenario : The client lost his private key and he is not able to access his server.
1 . Login to AWS console and create AMI of that EC2 instance;
Select the instance >> Right click >> Image and templates>>Create image
Then you will navigate to a new window and fill up the fields as below ;
Here highlighted the Reboot Option in the above figure ;
Which means, when we are creating an AMI of instance, The instance will be reboot. So we can enable No reboot option to reduce the downtime.
Then click on Create option and navigate to the EC2 window. Then we can see a popup notification message in that window.
We can also check the AMI creation from Images>> AMI’S ,
AMI : An Amazon Machine Image (AMI) provides the information required to launch an instance. You must specify an AMI when you launch an instance. You can launch multiple instances from a single AMI when you need multiple instances with the same configuration.
When the AMI successfully created, there will be create a snapshot of that particular instance.
We can check with the description in the above image (Highlighted)
There is two way to launch the instance using the created AMI.
First one: we can launch the instance by normal steps, There we select the AMI from MY AMI’s option.
Select the AMI and you will be navigate to a new window, then click on Review and Launch.
In the above image, If you want to change the instance type you can select, But it will not cause the AMI configuration and data.
Please note that you have to select the old EC2 instance’s security group before launching.
Then create a new private key for the new EC2 instance.
Fill the name field and download the private key to a safe place. Then click on Launch Instances.
Now we have created a new instance from the AMI without any downtime.
Please note that we have to associate the public IP from the old EC2 instances to the new EC2 instance.
So Dissociate the elastic IP from the old EC2 instance and associate the elastic IP with the new EC2 instance.
Then connect to the server by the new private key and terminate the old EC2 instance.
Method 2
By detaching the root volume
we have an EC2 instance with a demo site running on apache webserver.
The same scenario as I already mentioned above.
Here we are going to detach the root volume.
Before detaching the root volume. First, we have to stop the EC2 instance.
Instances >> Select the instance >> Instance state>> Stop Instance.
After the status instance state went STOPPED , Then we detach the root volume.
Volume >> Select the volume >> Right click >> Detach Volume
Then check the status of the volume, The status will be going to Available status after detaching.
Here the root volume successfully detached from the old instance. Then we create a new instance. And we will attach the root volume to the new instance as an additional volume.
Create a new instance with a new key pair and it’s download to a safe place, So we are going to attach the root volume.
Volume >> Select the volume >> Righ click >> Attach Volume
And select the Instance that we want to attach the volume and click on attach.
Check the attached volume from Instance >> Storage details.
Connect via ssh to the new instance and mount the new volume temporarily.
Copy the public key from the new instance to the old instance and unmount the device /dev/xvdf1.
Detach the root volume and attach to the old EC2 instance.
Select the volume >> right click>> Detach volume
Click on Yes, Detach
We have successfully detached the root volume and we are going to attach the root volume to the old instance.
Select the volume >> right click>> Attach Volume
Select the instance ID (please note , we can attach the volume even if the instance is stopped).
In next window , we have to give the exact device name to root volume as follows.
Then click on the Attach.
Check the volume state , and it will be in use state , Then start the stopped EC2 instance .
Connect the server via ssh using new private key , And check the demo sites files inside the document root.
Successfully accessed the server by using new private key .
Please note that, The new AWS console can directly connect to SSH via web console without the SSH key.
The console method may not work for all OSs and when the SSH port is changed.
Select the instance >> connect >> EC2 instance connect >> Click on connect.
Then you will connected to the Console .
Category : AWS, Linux
Add new commentSIGN IN