In this tutorial, we are going to learn about Amazon Elastic Compute Cloud(EC2).
Amazon Elastic Compute Cloud(Ec2) allows users to rent virtual machines on which to run their own computing functions. Ec2 provides a way to host your applications on the cloud at an affordable rate because data centers are much more expensive when you are not fully utilizing your services.
What makes Ec2 suitable for production?
- Ec2 provides resizeable compute capacity in the cloud.
- It reduces the time required to obtain and boot new server instances to minutes and allows you to scale faster.
- You pay for what you require
- The owner controls his own servers.
- Ec2 is very reliable, secure, and easy to start.
- It’s very inexpensive
- Secure login to your instance using key pairs
- You are provided with instance store volumes for temporary storage.
- It provides you with elastic IP addresses for dynamic cloud computing.
- It offers persistent storage volumes with the help of the Amazon Elastic Block store which is highly available and independent.
- Have AWS account
- Select which region to spin your instance
- Create key pairs for a secure connection to our instance via ssh.
Steps to Spin up EC2
1. Login to your AWS account
When you first login into your AWS account, you will be greeted with an interface like the one shown below.
2. Choose the region where you want to host your server. For me, I am using N.Virginia, Choose a region next to you.
3. From the search bar, search for EC2 and you will be taken to the Ec2 dashboard.
4. Create key pair for ssh login. This is critical whenever you want to log in via ssh. Go to key pair and click create key pair. Choose a name, key pair type, private key file format, .pem for Linux environment and .ppk for windows and lastly click create
5. Next is to create a security group that acts as a firewall for your instance to control inbound and outbound traffic. It’s easy to create, just click create input name, and description, choose VPC to use, and create different rules you want to allow.
6. Now it’s time to launch the instance. On the EC2 dashboard click on launch instance then input the name of the instance, then choose OS for that instance. Always choose free tier OS for experimentation to avoid incurring any expenses in the long run. The next thing is to choose your instance type. Select the t2.micro which is free tier eligible. Then you need to choose the key pair we created earlier. Move to network settings and choose the security group we created earlier also or you can create one if you didn’t create one at the beginning. For now, leave advance settings and click launch instance.
7. After you have successfully initiated the ec2 instance, click view all instances and you will see something like the below image.
8. The next step is to connect the instance so that we can do whatever we want with it. Click on the checkbox and click on connect. You will see the following being shown.
I always love connecting via ssh client, this gives me an isolated environment away from the Ec2 interface. So to connect via ssh follow the procedure shown in the image above.
Always use the best way that suits you to connect to your instance. From you can start running your intended functions of the instance.
9. Terminate your instance when you are done with your instance to avoid incurring extra costs. This is done by clicking instance state and clicking terminate.
Congrats on spinning up your first instance on AWS. Happy coding!