Play with your First EC2 instance
Amazon Web Services (AWS) offers a revolutionary cloud-based web service called Elastic Compute Cloud (EC2) that provides unparalleled computing capacity in the cloud. In this cutting-edge platform, users have the ability to rent virtual machines, called instances, that are fully customizable to meet their specific computing needs.
In this article, we will look into launching and configuring a virtual machine in the powerful and dynamic AWS cloud. We will log in to the machine using SSH authentication. Further, we will create a web page and publish it on AWS virtual machine. Let's begin …
Login to the AWS console and launch a new EC2 instance with the following details:
Instance Name: MyEC2Instance
AMI image: Amazon Linux 2023 AMI
Instance type:t2.micro
Key pair: MyEC2Instance_KP created with default RSA and pem options
MyEC2Instance_SG - allowed for SSH, HTTP and HTTPS
Storage: 1 volume(s) - 8 GiB
Once your Instance is running, connect to the instance using the EC2 Instance Connect option.
Once you are connected to the console, you can run the following commands to install a webserver and connect to it using HTTP:
yum -y update
yum install httpd -y
systemctl start httpd
systemctl enable httpd
systemctl status httpd
echo "<html>Hi This is my Test WebServer Page, Welcome to it</html>" > /var/www/html/index.html
systemctl restart httpd
Now, using the public IP of the VM, we can connect to web server
Let's also try to connect VM using some other common methods :
Using SSH command line:- we just need the .pem file which we saved when creating the instance:
C:\Users\offic\Desktop>ssh -i "MyEC2Instance_KP.pem" ec2-user@ec2-3-86-147-27.compute-1.amazonaws.com
The authenticity of host 'ec2-3-86-147-27.compute-1.amazonaws.com (3.86.147.27)' can't be established.
ED25519 key fingerprint is SHA256:gdV+dgiJdeFbU7i/ewwxCBvTZMfbAg7F9p6kD1wfzJs.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ec2-3-86-147-27.compute-1.amazonaws.com' (ED25519) to the list of known hosts.
, #_
~\_ ####_ Amazon Linux 2023
~~ \_#####\
~~ \###|
~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023
~~ V~' '->
~~~ /
~~._. _/
_/ _/
_/m/'
Last login: Sun Jul 9 00:01:32 2023 from 18.206.107.27
Using PuTTY: We can also connect to our EC2 host via any SSH client viz. Putty. For this, we just need to convert our .pem file to .ppk using the PuTTYgen utility. Ensure you are using the latest version of the PuTTY client.
Open the PuTTY client and enter your hostname address viz. ec2-user@ec2–3–91–208–245.compute-1.amazonaws.com and select your .ppk file under SSH->Auth->Credentials section.
Click “Open” and it will open a successful connection to your EC2 instance as follows:
If you face issues, the following guide is very useful for troubleshooting.
Feel free to leave a comment if you are still facing difficulty in connecting to the instance.
Do not forget to terminate the instance after you are done exploring it.