AWS EC2 is one of the very most popular services of AWS. It is a virtual computer where you can deploy your application.
And in this post, we are going to deploy our first application to the cloud from scratch.
Excited? Let’s follow the below steps.
Step 1: Log in to your AWS account and open the EC2 service
Login to your AWS account and in the search bar search for EC2 from the search result click on EC2
This will opens up the EC2 dashboard as per the below screenshot.
EC2 Dashboard
You can see lots of options on the EC2 dashboard but don’t worry about all those options as of now.
From the above screen just click on Lunch Instance and that will leads you to the next step.
Step 2: Add name and tag
This is the main configuration screen for the EC2 instance, in this screen, you will set up Compute capacity, Networking settings, and storage.
Give the Name of the instance as per your requirements.
You can also add tags to easily identify your instance. (Tag is very useful when you are working with multiple EC2 instances)
Name and tag
Step3: Choose AMI(Amazon Machine Image)
An AMI is a template that contains the software configuration (operating system, application server, and applications) required to launch your instance.
I am going with Amazon Linux 2 AMI which is in the free tier. choose as per your requirements there are other options available as well as you can see in the screenshot. e.g. macOS, Ubuntu, Windows, Red Hat, etc.
Note: If you are using it for learning purposes then make sure you are choosing the free tier otherwise you will get charged.
AMI
Step 4: Select the Instance type
So instance types are going to differ based on the number of CPUs they have, the amount of memory they have, and how much they cost.
I have a T2 micro selected. this one is free tier eligible, so it will be free to launch one of them during an entire month if we leave it running,
You could scroll down and look at other types of instances. For example, T1 micro is also free tier eligible, but that’s the older generation.
If you wanted to compare the instance types, you will just click on that link, and it will show you all the types of instances here. as well as how much memory they have and so on.
So right now, we’ll be using a T2 micro.
Instance Type
Step 5: Create Key pair
- The key pair is to log in to your instance. So it is required to create key pair.
- There is no key pair, so let’s go ahead and create a new key pair.
Enter the name of your choice, then you need to choose a key pair type, so we’ll be using the RSA encrypted.
For key pair formats, if you have Mac or Linux, or Windows 10, then you can use the .pem format.
If you have Windows less than version 10, for example, Windows 7 or Windows 8, then you can do a little shortcut and directly use a PPK, which is going to be used for PuTTY.
Step 6: Network settings
we are not going to touch anything in the network settings
The First security group created will be called launch-wizard-1, Here in the screenshot, it is launch-wizard-3 because I have already created 2.
we can define multiple rules, so the first rule we want to have is to allow SSH traffic from anywhere.
we also want to allow HTTP traffic from the internet, check mark allow HTTP traffic from the internet and this is because we’re going to launch a web server
We’re not going to use HTTPS for now, we don’t need to tick the second box.
Step 7: Configure storage
Let’s configure the storage, as we can see, we have eight gigabytes of gp2 root volume
In the free tier, we can get up to 30 gigabytes of EBS General Purpose SSD storage, And we only have one volume necessary.
If you go into advanced, you could configure them
one important thing to note in here is the deletion on termination. By default it is enabled to yes, That means that once we terminate our EC2 instance, then that volume is also going to be deleted.
Step 8: Add user data in the Advance tab
Next for advanced details, this is where it gets interesting. so let’s scroll down all the way to the bottom.
In User data, we will pass a script, so some comments, to our EC2 instance to execute on the first launch of our E2 instance and only the first launch.
And therefore, on the first launch, we want to be able to pass these commands right here.
Paste following code into user data
#!/bin/bash
# Use this for your user data (script from top to bottom)
# install httpd (Linux 2 version)
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html
- it’s going to update a few things, then install the HTPD web server on the machine, and then write aHTML file,
Step 9: Verify the installation
Go to EC2 dashboard and wait for sometime to change the instance state to Running.
Once it is running then copy IPv4 address and paste it into new browser.
Congratulations!! 🎉 you have successfully deployed your first ever website on EC2.
Conclusion
In this blog we learned how to deploy HTML content on Amazon Linux 2 instance. we learned about different types of AMI, Instance types, networking settings of EC2, storage, and user data.
Feel free to drop a comment if you face any issues or just share the feedback.
Enjoyed the content? Do follow me on medium for similar content. and don’t forget to share. 💻