EC2 Exercises

Launch and Connect to a Linux EC2 Instance

Amazon EC2 Instance

An EC2 instance is a virtual server in Amazon Web services terminology. It stands for Elastic Compute Cloud. We will create an On-Demand Linux EC2 instance. Please follow the steps.

  1. Login to AWS Console
  2. Click on the search window and type EC2 as shown in the figure below. Make sure you have set the AWS region in right corner of Console page. Here selected region is Mumbai
  3. Click on ‘Launch Instance’ button to Create an EC2 Instance.
  4. Choose an AMI. Select a Linux based AMI for practice purpose. While selecting make sure its ‘Free tier eligible’. (An AMI is an Amazon Machine Image. It is a template basically of an Operating System platform which you can use as a base to create your instance)
  5. Choose Instance Types. As default, select the ‘t2-micro’ instance type and click on “Configure Instance Details” for further configurations as shown in the figure below.
  6. Configure Instance. Keep everything default and click on ‘Add Storage’ to provide storage.
  7. Add Storage. In the Add Storage step, you’ll noticed that the instance has been automatically provisioned a General Purpose SSD root volume of 8GB. You can change your volume size and can change the volume type. Click on “Add Tags” to provide tags
  8. Add Tags. A tag consists of a case-sensitive key-value pair. A tag can be provided to the instance with a key-value pair. This gives visibility to the AWS account administrator when there are lot number of instances. For Ex: key: env, value: development
  9. Configure Security Groups. You can restrict traffic on your instance ports. This is an firewall mechanism provided by AWS. Here you can keep the default security provided by AWS. Make sure the TCP port ’22’ open to do the ssh communication to the Linux instance.  This security group is for practice purpose only. If you create it for your project, make sure not to open it publicly. You can change your security group name by providing a good name. Click on “Review and Launch”.
  10. Review Instance Launch. In this step, we will review all our choices and parameters and go ahead to launch our instance.
  11. Select an existing key pair or create a new key pair. 
    • A key pair consists of a public key that AWS stores, and a private key file that you store. Together, they allow you to connect to your instance securely. For Windows AMIs, the private key file is required to obtain the password used to log into your instance. For Linux AMIs, the private key file allows you to securely SSH into your instance)
  12. If you are creating a new key pair, then download the .pem file and save it to a safe place.
  13. Launch your Instance
  14. Click on the ‘Instances’ option on the left pane where you can see the status of the instance as ‘Pending’ for a few seconds.
  15. Once your instance is up and running, you can see its status as ‘Running‘. Your instance is running and you need to connect it from your local machine.
  16. Select the instance and copy the public address.
  17. If your local system is Windows system, then first convert the .pem file to .ppk file using ‘PuTTYgen‘ tool. You can download the Putty and PuTTYgen tool from internet.
  18. Open the putty tool and setup your connection. Add your ec2 instance public ip in the Hostname section and port as 22 as shown below.
  19. Provide your ppk file path in ‘Auth’ option in the left panel. Please refer the image below.
  20. Select the ‘Session‘ option left top of the window. Then click the ‘Save‘ button.
  21. Now click on the Open button to connect to your virtual instance.
  22. Once you connect, you will successfully see the Linux prompt. Provide the user name as ‘ec2-user’ and enter into the instance.
  23. Do some operation if required.
  24. You can ‘Terminate’ the instance, if not using it. You can delete your instance when you no longer need it. You can’t connect to or start an instance after you’ve terminated it. AWS stops charging you for that instance.
  25. You can Stop the instance. When you stop an instance, it shuts down. AWS don’t charge usage for a stopped instance, or data transfer fees, but its chargeable for the storage for any Amazon EBS volumes. You can start the stopped instances any time.

Launch and Connect to a Windows EC2 Instance

  1. Login to AWS Console
  2. Click on the search window and type EC2 as shown in the figure below. Make sure you have set the AWS region in right corner of Console page. Here selected region is Mumbai
  3. Click on ‘Launch Instance’ button to Create an EC2 Instance.
  4. Choose an AMI. Select a Windows based AMI for practice purpose. While selecting make sure its ‘Free tier eligible’.
  5. Choose Instance Types. As default, select the ‘t2-micro’ instance type and click on “Configure Instance Details” for further configurations as shown in the figure below.
  6. Configure Instance. Keep everything default and click on ‘Add Storage’ to provide storage.
  7. Add Storage. In the Add Storage step, you’ll noticed that the instance has been automatically provisioned a General Purpose SSD root volume of 30 GB. Click on “Add Tags” to provide tags
  8. Add Tags. A tag consists of a case-sensitive key-value pair. A tag can be provided to the instance with a key-value pair. This gives visibility to the AWS account administrator when there are lot number of instances. For Ex: key: env, value: development
  9. Configure Security Groups. You can restrict traffic on your instance ports. This is an firewall mechanism provided by AWS. Here you can keep the default security provided by AWS. Make sure the TCP port ‘3389’ open to do the RDP communication to the Windows instance.  This security group is for practice purpose only. If you create it for your project, make sure not to open it publicly. You can change your security group name by providing a good name. Click on “Review and Launch”.
  10. Review Instance Launch. In this step, we will review all our choices and parameters and go ahead to launch our instance.
  11. Select an existing key pair or create a new key pair. 
    • A key pair consists of a public key that AWS stores, and a private key file that you store. Together, they allow you to connect to your instance securely. For Windows AMIs, the private key file is required to obtain the password used to log into your instance.
  12. If you are creating a new key pair, then download the .pem file and save it to a safe place.
  13. Launch your Instance
  14. Click on the ‘Instances’ option on the left pane where you can see the status of the instance as ‘Pending’ for a few seconds.
  15. Once your instance is up and running, you can see its status as ‘Running‘. Your instance is running and you need to connect it from your local machine.
  16. To connect to a Windows instance, you must retrieve the initial administrator password and then enter this password when you connect to your instance using Remote Desktop.
  17. Select the instance and click on the ‘Connect‘ button.
  18. From the “Connect to instance” window, select the RDP client tab, and then choose ‘Get password’
  19. Click on the ‘Browse’ button and navigate to the private key (.pem) file you created when you launched the instance. Select the file and choose Open to copy the entire contents of the file to this window.
  20. Click on the ‘Decrypt Password’ button. The console displays the default administrator password for the instance under Password. Save the password in a safe place. This password is required to connect to the instance.
  21. Open ‘Remote Desktop Connection’ from your windows system. (simply type RDP in the search bar)
  22. Choose ‘Download remote desktop file‘ and download to your local system.
  23. Open the remote desktop file and ‘connect‘ to the instance. It opens a dialog with the administrator account is chosen by default. Copy and paste the password that you saved previously.
  24. Due to the security certificates, you may get a warning that the security certificate could not be authenticated. Click on ‘yes‘ button to connect to your instance
  25. Now your Windows EC2 instance connected and you can see the Windows UI.
  26. Do some windows operation if required.
  27. You can ‘Terminate’ the instance, if not using it. You can delete your instance when you no longer need it. You can’t connect to or start an instance after you’ve terminated it. AWS stops charging you for that instance.
  28. You can Stop the instance. When you stop an instance, it shuts down. AWS don’t charge usage for a stopped instance, or data transfer fees, but its chargeable for the storage for any Amazon EBS volumes. You can start the stopped instances any time.

Check EC2 Access Metadata
Install Apache Web Server on EC2 Instance
Use an Elastic IP in EC2 Instance

EC2 Exercises

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top