DEV Community

Anudeep Reddy
Anudeep Reddy

Posted on • Originally published at blog.anudeepreddy.me

Get started with AWS EC2

Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage, content delivery and other functionality.
The AWS Cloud spans 69 Availability Zones within 22 geographic regions around the world, with announced plans for 13 more Availability Zones and four more AWS Regions in Indonesia, Italy, South Africa, and Spain.
One of their services is Amazon Elastic Compute Cloud, which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet.

This Post is all about the Amazon EC2 what is it?, Creating and accessing your own EC2 instance

What is EC2?

EC2 stands for Elastic Compute Cloud. It is a web service which allows people to run applications and workload on virtual machines in the AWS cloud.
Basically they are the virtual servers in the cloud which the users can access and deploy their applications to. The benefits of using Amazon EC2 include the following:

  • ELASTIC WEB-SCALE COMPUTING
  • COMPLETELY CONTROLLED
  • FLEXIBLE CLOUD HOSTING SERVICES
  • INTEGRATED
  • RELIABLE
  • SECURE
  • INEXPENSIVE
  • EASY TO START

Setting up a EC2 instance is pretty straight forward. You can choose an instance type and the operating systems from a wide variety of options available in the AWS console. The user is given control to setup the memory and network configuration. AWS charges users on hourly basis for EC2. The users can also assign a Elastic IP(Static IP) to their EC2 instance. If you want to setup a domain and need a DNS then AWS Route 53 is at your service.

Creating your own EC2 instance

If you are here then let me assume that you have already signed up to the AWS and added a Payment option. If you are haven't done any of that yet then go ahead and do it now.

  • Sign in to your AWS console. Head over to this link to sign in https://aws.amazon.com/
  • Your console should look something like this.

AWS Console

  • Now click on the services in the top navigation bar and then click on EC2 that is under compute section to navigate to the EC2 dashboard.
  • Now in the EC2 dashboard you will see a button called Launch Instance click on that to start setting up your instance.
  • In the first step you will be asked to Choose an Amazon Machine Image(AMI). AMI is basically the operating system that you want to run in your EC2 instance. Few images are free to use where as there are few images for which we need to pay additional licensing fees.

EC2 AMI Setup

  • We will be choosing Ubuntu Server 18.04 LTS (HVM), SSD Volume Type for this tutorial. Feel free to choose your own.
  • In the next step you will be asked to choose an Instance type, Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Instances are virtual servers that can run applications. They have varying combinations of CPU, memory, storage, and networking capacity, and give you the flexibility to choose the appropriate mix of resources for your applications.

EC2 Instance Type

  • You can now just Review the settings and Launch the instance directly or Configure other instance details, Add aditional storage and also configure the security group.
  • We will just leave the other details unchanged and head over to the 6th step to configure the security group.
  • This section allows you to configure the firewall rules that control the traffic to our instance.
  • By Default the instance allows traffic on port 22 for establishing a SSH connection to the Server.
  • Now let us configure it to allow http traffic on port 80.
  • Click on Add Rule and populate the type field to HTTP and all the other fields are automatically filled.

EC2 firewall

  • Now click on Review and Launch button at the bottom. Now you will see the entire configuration for your instance. If everything looks good then click on launch.
  • Once you click on launch you will be asked to create or use a existing Public key and Private key pair. Create a new key pair, Give the key pair a name and once you download the key click on Launch. This key will be used to authenticate us to the EC2 instance via SSH.

Accessing your EC2 Instance

Once you are done with creating your EC2 instance then you will be redirected to a page where you can access all your running instances.

  • Select the instance that you want to connect to, Once you have done that the connect button will be enabled. Clicking on the button will give you instructions to connect to your instance.
  • Open up a terminal and navigate to the location where you stored your key that you downloaded during the creation process.
  • For me it's Downloads. If you are on windows machine then fire up bash or terminal in linux and OSX.
  • Give your key the right permissions by typing this command: sudo chmod 400 [PATH/TO/THE/KEY]

Terminal

  • Once you are done doing that Copy down the example command shown in the EC2 dashboard and run it in your terminal.
  • That's it you are now connected.

Terminal-connected

Setting up a apache webserver

As you are connected to the machine via SSH, You now have a terminal access to the virtual machine and you can run commands to perform operations on it.

We have already allowed traffic on port 80, so now we can access our website if we host one on this virtual machine. To setup a simple webserver let us install apache.

sudo apt-get update
sudo apt-get install apache2 -y
Enter fullscreen mode Exit fullscreen mode

Now type the following command to start the apache server.

sudo service apache2 start
Enter fullscreen mode Exit fullscreen mode

Now open your web browser and navigate to the IP assigned to your EC2 instance. You should be able to see the following page.

Apache home page

We have successfully installed apache now.
If you want to host your own website then modify the files located at /var/www/html. That directory contains the files of your website.

Assigning an Elastic IP

The IP address that is currently assigned to the Instance will be lost if you reboot the instance. So if you want your instance to have a static IP then AWS offers something called Elastic IP. You can assign a static IP to the instance using Elastic IP.

Follow these steps to assign a Elastic IP:

  • In the sidebar of the EC2 instance dashboard you will find Elastic IP under Network and security.
  • Click on allocate elastic IP.
  • Once that's done. Select the IP and click on actions and click on Associate Elastic IP address.
  • In the next page select the Instance to which you want to assign that IP to.
  • Click on Associate and you are done. The Elastic IP is associated to your instance.

NOTE: The Elastic IP is a chargable service.
Check out the pricing in the AWS pricing page

Final Thoughts

AWS EC2 is an easy way to get started with cloud computing as a beginner. AWS also provides one year free tier services if you setup your payment information. With the AWS free tier you can access all the basic services provided as a part of AWS for free. Claim your free one year now by signing up and providing your payment info.
Navigate to this page to know more https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc

Thank you!

Feel free to leave your comments below

Top comments (0)