Linux | Cloud | DevOps | Scripting

Breaking

EC2 INSTANCE CREATION

Practicals Covered:
  1. Launch Linux EC2 Instance in AWS
  2. Launch Windows EC2 Instance in AWS
  3. Connect Local Drive into Windows EC2 Instances 
  4. Protect any Instance from Terminate
  5. Change Shutdown Behavior

Practical-1: LAUNCH LINUX EC2 INSTANCE IN AWS

AWS > Services > EC2 > Launch Instance (to launch a Virtual Server) > [*] Free Tier Only > Select any image. For e.g. I am selecting 'Red Hat Enterprise Linux 7.6 (HVM) - 64 bit' > Select > Instance Type: 't2.micro' > Configure Instance: Number of Instance: 1 > Auto-assign Public IP: Enable > Next: Storage > Next Tags: Click to add a Name Tag > Key: Name & Volume: linux-srv1 > Next: Security Group: Assign a security group: (*) Create a new security group OR ( ) Select an existing security group > Security group name: 'linux-access' > Description: Created SG to access Linux Server > Review and Launch > Launch > Launch Instances

But the 'Launch Instances' Button is not highlighted because we need a public key and a private key. For this, we need to create a new key pair or we can select an existing key pair. There is also one more option in the drop-down list, 'Proceed without key pair', but this is not safe so, we are not using that now.

If we use Create a new key pair, then two keys will be generated here Public key and Private key. The private key will be downloaded on our System and Public key will go to AWS.

Create a new key pair > Key pair name: divsecuritykey > Download Key Pair > (key is generated by the same name with '.pem' format) > Launch Instance.

Right now this is in Pending stage but within a few moments, this will be in the running stage. As our instance is running, we can see hostname and Public & Private IP of our instance in the Description tab. We can access our instance in both ways, using IP or hostname. We got our key in .pem format but putty does not support .pem format. Putty uses '.ppk' format. So we need to convert this .pem  file into .ppk format using software named 'PuTTYgen'. Load our key in PuTTYgen and Save it in .ppk format.

PuTTYgen > Load > Select All Files (*.*) in front of File_Name > Select .pem file > Open > This will show us a notice that 'Successfully imported foreign key' > OK > Click on 'Save Private Key' > Name: divsecuritykey.ppk

NOW, copy the public key from AWS and paste that on PuTTY in Session tab > then go to Connection > Click on plus sign (+) on SSH > Click on Auth > Locate Private key file for authentication, by clicking on Browse > Open


Now PuTTy terminal will open. Default username for Linux instance is 'ec2-user'. Provide username ec2-user and now we have access to our instance. Enjoy!!!

Q. If we are not able to reach our instance, how can you troubleshoot?
A. First of all check SG (Security Group). After that check public key and private key. Most often at the time of creating an instance, we select the key whose private key is not present in our computer. As a result, we got the instance but we could not provide its private key. So, before selecting the public key from the drop-down list, we must check its private key is present in our computer or not.



Practical-2: LAUNCH WINDOWS EC2 INSTANCE IN AWS

AWS > Services > EC2 > Launch Instance (to launch a Virtual Server) > [*] Free Tier Only > Select any image. For e.g. I am selecting 'Microsoft Windows Server 2012 R2 Base - 64 bit' > Select > Instance Type: 't2.micro' > Configure Instance: Number of Instance: 1 > Auto-assign Public IP: Enable > Next: Storage > Next Tags: Click to add a Name Tag > Key: Name & Volume: win-srv1 > Next: Security Group: Assign a security group: (*) Create a new security group OR ( ) Select an existing security group > Security group name: 'win-access' > Description: Created SG to access Linux Server > Review and Launch > Launch > (As we have created a key-pair in Linux instance practical, we can use that here) > Launch Instances > View Instances.

Right now this is in Pending stage but within a few moments, this will be in the running stage. As our instance is running, we can see hostname and Public & Private IP of our instance in the Description tab.

Select the windows instance we launched right now > Copy 'Public Key' from Description > Open RDP (We can open Remote Desktop Connection by using 'Windows + R' type 'mstsc' and hit enter) > Paste Public Key here > Connect > Provide default username for Windows instance that is 'Administrator' > Password: ?

For Password Select Windows Instance > Actions > Get Windows Password > this is showing our provided Public Key named 'divsecuritykey' and we need to provide Private Key in '.pem' format > Browse > Provide key > Decrypt Password.


As we click on Decrypt password, this will provided us a password which we can use in RDP directly.


After providing password click on OK > Authorize Certificate by clicking on Yes.
Now we have access to our instance. Enjoy!!!



Practical-3: CONNECT LOCAL DRIVE INTO WINDOWS EC2 INSTANCE

Select Windows Instance > Copy Public IP from Description > Run RDP > Paste IP > Click on Show Options > Local Resources > More > Expand Drives > Tick on the Drive we want to map on Server > OK > Connect > Connect > Provide password > Now we are connected to the Windows instance


Open My Computer > here we can see our mapped drive > Now just drag the files, we want to copy in this instance.

To unlink or disconnect mapped drive, again we need to perform the same task and uncheck the drive, which we tick at the time to map.



PRACTICAL-4: PROTECT ANY INSTANCE FROM TERMINATE

AWS > Services > EC2 > Select the instance we want to protect > Actions > Instance Settings > Change Termination Protection > Enable.

Now, as a user will click on terminate the instance, the termination button will not work. To delete this instance we need to perform the same exercise once again and again change the termination protection and Disable it.



PRACTICAL-5: CHANGE SHUTDOWN BEHAVIOR

AWS > Services > EC2 > Select the instance > Actions > Instance Settings > Change Shutdown Behavior > Shutdown behavior: Terminate > Apply

Now, if the user performs shut down the instance, the instance will be Terminated.

NOTE:

We can update Shutdown Behavior at the time of Instance Creation also. This activity we can do when we Add Storage. Just Check or Uncheck in the checkbox in front of Delete on Termination.







No comments:

Post a Comment

Pages