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.
- Login to AWS Console
- 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
- Click on ‘Launch Instance’ button to Create an EC2 Instance.
- 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)
- 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.
- Configure Instance. Keep everything default and click on ‘Add Storage’ to provide storage.
- 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
- 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
- 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”.
- Review Instance Launch. In this step, we will review all our choices and parameters and go ahead to launch our instance.
- 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)
- If you are creating a new key pair, then download the .pem file and save it to a safe place.
- Launch your Instance
- Click on the ‘Instances’ option on the left pane where you can see the status of the instance as ‘Pending’ for a few seconds.
- 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.
- Select the instance and copy the public address.
- 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.
- 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.
- Provide your ppk file path in ‘Auth’ option in the left panel. Please refer the image below.
- Select the ‘Session‘ option left top of the window. Then click the ‘Save‘ button.
- Now click on the Open button to connect to your virtual instance.
- Once you connect, you will successfully see the Linux prompt. Provide the user name as ‘ec2-user’ and enter into the instance.
- Do some operation if required.
- 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.
- 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
- Login to AWS Console
- 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
- Click on ‘Launch Instance’ button to Create an EC2 Instance.
- Choose an AMI. Select a Windows based AMI for practice purpose. While selecting make sure its ‘Free tier eligible’.
- 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.
- Configure Instance. Keep everything default and click on ‘Add Storage’ to provide storage.
- 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
- 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
- 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”.
- Review Instance Launch. In this step, we will review all our choices and parameters and go ahead to launch our instance.
- 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.
- If you are creating a new key pair, then download the .pem file and save it to a safe place.
- Launch your Instance
- Click on the ‘Instances’ option on the left pane where you can see the status of the instance as ‘Pending’ for a few seconds.
- 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.
- 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.
- Select the instance and click on the ‘Connect‘ button.
- From the “Connect to instance” window, select the RDP client tab, and then choose ‘Get password’
- 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.
- 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.
- Open ‘Remote Desktop Connection’ from your windows system. (simply type RDP in the search bar)
- Choose ‘Download remote desktop file‘ and download to your local system.
- 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.
- 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
- Now your Windows EC2 instance connected and you can see the Windows UI.
- Do some windows operation if required.
- 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.
- 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