Amazon Elastic Compute Cloud (EC2) instances are like virtual servers you can rent from Amazon. The keyword here is Elastic. The EC2 instances come with a feature called Auto Scaling. This is the equivalent of the number of servers stretching automatically when traffic increases and then shrinking back down again when the traffic drops off.
We’ll launch an instance and use it to run an NginX web server which will be accessible from anywhere using a URL. So without further ado, let’s get started.
Search for EC2 in the AWS search bar. From there click the launch instance button.
Now you would see a screen to choose an AMI. AMIs (Amazon Machine Images) are nothing but virtual machine images.
For this shot, we’re going to select the Amazon Linux 2 AMI (HVM), SSD Volume Type with the
On the instance type screen, we select the kind of hardware we want to be allocated to our
From here click on review and launch and finally on the next screen click on launch.
Now to connect to this instance through
In the first pulldown on the popup you see, click on “create a new key pair”.
Let’s name it as ec2demo. Then click the “download Key pair” button and finally click the “launch instances” button.
On the next screen, click on “view instances”.
Once you confirm that the instance state is running, click on the checkbox in the first column for this instance and then click on “connect” in the top bar.
Go to the SSH client and if you follow the instructions there you should have SSH access to your instance.
What this basically did was use the encoded private key we downloaded to connect via SSH to the instance which already had the associated public key installed.
Now let’s install NginX on this machine. NginX is available from the AWS extras repository.
You can confirm this by running the following command:
amazon-linux-extras list | grep nginx
sudo amazon-linux-extras install nginx1
sudo service nginx start
sudo service nginx status
Now that we have our EC2 instance all setup, let’s head back to the AWS console. If we select the instance, we’ll see information related to it on the bottom of our screen as shown in the image below:
The Public IPv4 DNS is the URL we can use to see the NginX starter page from any machine.
If you’ve run servers before you’d know that allowing unfiltered internet traffic to your server means exposing it to so many security threats. Amazon uses security groups to solve this. These act as firewalls that allow us to expose only the parts of our server that are configured for public internet traffic.
Since we didn’t configure our security groups while launching the EC2 instance, Amazon assigned the standard security group to it.
On the next screen, you will see one inbound and one outbound rule. The outbound rule allows our EC2 instance to communicate with anything on the internet. The inbound rule on the other hand says that anyone can connect to our instance using SSH. Click on the edit inbound rules button to add another inbound rule.
We’ll add a rule to allow
HTTP traffic from anywhere onto our EC2 instance. Add the rule shown below and then click on “save rules”.
After doing this if you go to the previous URL you should see the NginX starter page.
Please note that you should navigate to
Before we wrap up, I want to show you one last thing. Just like we used the Amazon Linux 2 AMI (HVM), SSD Volume Type AMI for this EC2 instance, you can create an AMI from this instance. This would mean that when you launch another instance using this created AMI you wouldn’t have to install NginX again.
To do this, select your instance and go to:
Now once the AMI is ready and you navigate to the AMIs section using the nav menu on the left, you should be able to launch an instance using this image.
View all Courses