What is Amazon EC2 and how to launch an EC2 instance? Step by step guide
Amazon Elastic Cloud Compute (EC2) is a web service that allows you to deploy your applications in the cloud. Amazon EC2 comprises of both Windows and Linux based operating systems. But before we dive into launching an Amazon EC2 instance, first of all, let’s have an overview of virtual machines.
What is a virtual machine?
A virtual machine which is also known as a guest is created within a computing environment, called a host. A virtual machine (VM) is a software program or operating system that behaves like a separate computer and carries out various tasks such as running applications and programs. Also, it is an application environment that is installed on software while using dedicated hardware.
Now, let’s talk about Amazon Elastic Cloud Compute (EC2)
Amazon Elastic Compute Cloud (Amazon EC2) is a service which allows individuals to run various application programs in the computing environment. Similarly, it is an AWS service that provides scalable computing capacity, allowing us to scale up or down as per the change in requirement and minimizes the need to forecast the traffic.
Furthermore, with EC2, we can launch as many or as few virtual servers according to our requirements. And additionally, it allows us to configure security and networking as well as managing the storage.
Launching an Amazon EC2 instance
Step 1: First of all we are required to Sign In to our AWS Management Console.
Note: If you require guidance to Sign In to your AWS Management Console from your AWS Educate account, you can refer to my previous blog as provided below.
How to Sign In to your AWS Educate Account?
Here, in I will be discussing on how to Sign In to your AWS account after your AWS Educate Application is Approved.
Step 2: In find services, search for “EC2”.
Step 3: After you search for “EC2” in “find services”, you will be redirected to the EC2 Dashboard as shown below. Here, you need to scroll down and click on “Launch instance”.
In Amazon EC2, virtual computing environments are known as instances. Here, our instances will be launched in the US East (N. Virginia) Region.
Step 4: Now, we are required to “Choose an Amazon Machine Image (AMI)”. For now, we are going to select “Ubuntu Server 18.04 LTS”. Now, scroll the page and search for “Ubuntu Server 18.04 LTS” and click on the “Select” button.
AMI refers to Amazon Machine Images which comprises of pre-configured templates for the instances.
Step 5: Here, we are required to “Choose an Instance Type”. For now, we are selecting the “Free tier eligible” option as shown in the image below. Then, after selecting the option, click on the “Next: Configure Instance Details” button.
In this stage, we need to select the family for our instance, CPU, it’s type, memory, etc. as per the requirement of our virtual server.
Note: You can view various types of Amazon EC2 instances from the link provided below.
Amazon EC2 Instance Types - Amazon Web Services
Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Instance types comprise…
Step 6: In the “Configure Instance Details” stage, for now, we are not going to configure or make changes. Hence, click on “Next: Add Storage”.
In this stage, we can configure the instances, provide multiple instances, and provide network, subnet, etc. as per our requirement.
Step 7: Now, we need to “Add Storage” for our instance. Then, click on “Next: Add Tags”
Here, in “Add storage” we are defining storage type i.e. Hard drive for our instance according to our requirement. Then, we can provide the storage capacity in the Size(GiB) column and type of the hard drive in the Volume Type column.
Step 8: Here you are required to “Add Tags” for your Amazon EC2 instance. So, click on the “Add Tag” button as shown in the image below.
If we add tags to our Amazon EC2 instance, it helps us to manage our instances, images, and other Amazon EC2 resources. Here, tags enable us to categorize our AWS resources in multiple ways.
Step 9: Now, we provide “Key” and “Value” as per our convenience. For now, we are providing “CreatingEC2” and “LearningEC2” respectively. Then, click on “Next: Configure Security Group” button.
Step 10: Here in this stage we are required to “Configure Security Group” for our EC2 instance. For now, we are providing, rules as “SSH” and “HTTP”. Also, you can provide “Protocol”, “Port Range”, “Source” and “Description” to the Rule. If you need to add in the rules, you can click on the “Add Rule” button. Furthermore, we are providing the “Source” of “HTTP” as “Anywhere” so that it can be accessed from any place. Then finally, click on the “Review and Launch” button.
In Amazon EC2, a security group acts as a virtual firewall to control incoming and outgoing traffic. Here, inbound rules control the incoming traffic to your instance, and outbound rules control the outgoing traffic from your instance. If we are required to launch our web application on our EC2 instance then we add rules as “HTTP”. Also, the source is provided “Anywhere” in case of “HTTP” because web applications should be allowed to be any place but in case if you want to open the web application only from particular IP address then you are required to select “My IP” option from the drop-down list.
Step 11: In the “Review Instance Launch” stage, you are required to review all the configurations which you have made and finally click on the “Launch” button.
Step 12: Now, a pop up appears. Here, you are required to “Select an existing key pair or create a new key pair”. Select “Create a new key pair” from the drop-down.
If you are willing to create a new EC2 instance then select “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, it allows you to connect to your EC2 instance securely.
Step 13: Now, provide a “Key pair name”. For now, we are providing it as “Workshop1”. Then, click on the “Download Key Pair” button.
After clicking on the “Download Key Pair” button, a “.pem” file gets downloaded to our PC. It’s our private key file that can be used to connect to our EC2 instance. Hence, we need to make sure to keep our “.pem” file in a secured file location.
Step 14: Click on the “Launch instances” button.
Step 15: Finally, now your instance is now up and running.
Step 16: Now, go to “EC2 Dashboard” and click on “Instances” to view the instance which had been currently created.
Step 17: Now, for connecting to our virtual server, first of all, right-click the instance which you have recently created and click on “Connect” as shown in the image below.
Step 18: Now, a pop-up appears. Here, you are required to select a “Connection method” for connecting to your EC2 instance. For now, we are selecting “A standalone SSH client”.
There are multiple “Connection method” to connect to your EC2 instance. “A standalone SSH client” option can be selected in case if you are required to connect to your instance using an SSH client. Likewise, you can select the “Session Manager” option if you have to connect to your instance using Session. Finally, you can select “EC2 Instance Connect (browser-based SSH connection)”, if you want to connect to your instance using a browser-based client, the Amazon EC2 Instance Connect CLI, or the SSH client of your choice.
Step 19: First of all we are required to open an SSH client. Now, go to the location where you have downloaded the “.pem” file. Then, right-click in the file explorer and click on “Git Bash Here” as shown in the image below.
Step 20: Hence, for now, we are using Git Bash as our SSH client.
Step 21: Here, you can execute the command as “ls -al Workshop1.pem”.
‘ls -la’ command is used to show all the files and folders, including hidden files of the directory. It also shows the permission settings of the file which is represented in the form of a string of characters which is further classified into four sections:
- File type: There are a total of three types of files. They are: a regular file (–), a directory (d), or a link (i).
- File permission of the user (owner)
- File permission of the owner’s group
- File permission of other users
In the above figure, ‘r’ represents ‘read’ and ‘w’ represents ‘write’. Furthermore, there is still one more character which is not present in the above figure i.e. ‘x’ which represents ‘execute’.
Note: If you want to have a look at some of the basic shell commands, you can refer to my previous blog provided below.
Some Basic Shell commands
Before we dive into Git commands, it would be better for us to become familiar with some of the basic shell commands…
Step 22: Since the .pem file should be granted permission to read-only, we are going to use chmod command to grant permission for the user to read the file. Hence, we provide command as “chmod 400 Workshop1.pem”.
‘chmod’ command provides the user read permission and removes all other permission.
Step 23: Now, we can connect to our instance using its Public DNS. Hence, we can copy the ssh command i.e. ‘ssh -i “Workshop1.pem” ubuntu@ec2–52–23–213–23.compute-1.amazonaws.com’ as shown image below.
Step 24: Paste and execute the command in Git Bash as shown in the image below. Furthermore, after the question appears as “Are you sure you want to continue connecting (yes/no/[fingerprint])?”, enter ‘yes’ to connect to the EC2 instance.
Step 25: Finally you are now connected to your EC2 instance which contains Ubuntu OS.