Quick steps to launch your first AWS EC2 instance and SSH into it to create a webpage

Hey guys!!
If this is your first time working with AWS and you want to launch an EC2 instance, here is what you need to do. 

Firstly, you need to have an AWS account, if not, you can create one on AWS right now. AWS provides 12 months of free tier for its customers, you can anytime go @  AWS Free Tier and checkout which services are free and for how long.

So, I think by now you must have an AWS account. Log in to your account and search for EC2 Dashboard. Now, before creating an EC2 instance make sure you are in the region that is close to you, for me it is Asia Pacific (Mumbai), but you have to choose the region that is according to your location. 

Now, when you are in the EC2 Dashboard you see there is 0 running instances, for creating a new instance click on 'Launch Instance'. 




1) Choose AMI
When you click on 'Launch Instance', you'll land on Choose AMI screen and you will see multiple options for selection. AMI stands for Amazon Machine Image, which is basically the software and the operating system that you want to launch on the server. 




2) Choose an Instance Type
Here you can select the type of machine, number of vCPUs and memory that you want to have. Select the free tier eligible option and move to next step.




3) Configure Instance
Here you can select the number of instances you want to launch and other configurations.
I will leave this to default.




4) Add Storage
Select the amount of storage you want your instance to have, for free tier you can choose up to 30 GB of EBS. I'll leave this to default and move to next step.




5) Add Tags
Tags are basically key-value pairs which helps you to identify instances.




6) Configure Security Group
A security group is a set of firewall rules that control the traffic for your instance. The basic configuration that you need here is of SSH, which will allow you to access your server. So allow SSH on port 22 and for source you can keep it custom 0.0.0.0/0, which means any IP, for now as it is just a learning tutorial but you might want to change it in case you want to increase the security.




7) Review
Review your settings and click on 'Launch'. Now you will be asked to create a key pair, this key pair will allow you to access using SSH into the machine you just created. Create the key pair and download it, make sure to keep it safe as you will not be able to download it again and never ever share your ssh key with public. Click on 'Launch Instances' and voila! Your instance will be launched in few seconds, when done, click on 'View Instances' and you will see your newly created instance here. 







How to access your newly created instance?

Windows user: 
For Windows you can download WinSCP, FileZilla or any other SSH client application.   

Linux/Ubuntu user:
In Ubuntu, you can simply open the terminal and use below command to access the server.
sudo ssh -i {pem file path} {instance username}@{instance IP}

As I have a Windows system, I'll be using WinSCP to SSH into the instance.

To SSH into the server, you will need to provide Host name which you can get by selecting your instance on AWS and you can see the IP in Details section (refer last image). The Public IPv4 address is your host name with port number as 22.

 The username for Amazon Linux AMI is by default 'ec2-user' and in place of password we will be using the key pair that we created earlier. You can add the key in Advanced section, click Ok, save the settings and click Login.


In the top bar you can see putty icon, select that to access the terminal.


You can now install apache on it and run your first webpage.

 To install apache webserver, you need to first update the packages, so run below command for that:

sudo yum update -y

Install httpd using below command:

sudo yum install -y httpd

To start the service and make sure it remains enable, run below commands:

sudo systemctl start httpd.service
sudo systemctl enable httpd.service

Your webserver is successfully installed and now you can go on path /var/www/html/ to create your first webpage.

But before this you need to add a rule in your Security Group's Inbound rules, to allow the webpage to be accessed from browser, which requires HTTP. So, go to your instance again and in the Security section you will see Inbound rules, edit it and add HTTP on port 80.


Now, hit the bowser with your instance's public IP and you will see the default apache page, which means that Apache is successfully installed and you can access your server through browser.


For creating a webpage, using putty go to path /var/www/html and create a file index.html. Use nano to edit it, add your content and save it. Check the browser again with http://{public IP} and you can see your webpage now.



Thank you for visiting my blog.

Author: Bushra Fatima

Popular posts from this blog

AWS Load Balancer

Sitemaps and Indexing