How to Launch EC2 instances?
What’s AWS?
AWS is one dominating cloud platform service that serves businesses with scalable, reliable, and low-cost infrastructure.
With a varied suite of services offered under the AWS environment, one of the most common services is Amazon EC2 (Elastic Compute). Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic.
In this article, we are going to dive step by step into building an AWS EC2 instance and connecting to that EC2 instance. We are going to jump straight into the AWS EC2 console.
What is Amazon EC2 Instance?
An Amazon EC2 instance acts as a virtual server in Amazon’s Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure. As per the AWS documentation.
"You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage. "
Launching AWS EC2 Instance from AWS Console
1. Login into your AWS Account and open EC2-Dashboard
Navigate to the AWS EC2 Console & open the EC2 Dashboard, it’ll look something like this.
To create a Ubuntu instance on AWS, you first need to select an EC2 region. In this tutorial we will be using the us-east-1 region as it has low latency and availability for us.
Click Launch Instance, under the “Launch Instance” section.
2. Fill up the name of your instance
Enter the desired name for your instance, you can change it later.
3. Select Application & OS Image or AMI
AMI stands for Amazon Machine Image, it’s an OS that will be installed on the server you’re creating. There are a bunch of varieties to choose from like Ubuntu, Windows, Mac OS, etc.
4. Select the 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 the next step (create new key pair)
5. Create key pair
Key pairs allow you to connect to your instance securely.
Enter the name of the key pair below & store the private key in a secure and accessible location on your computer. \**
You will be needing it later to connect to your instance.
6. Configure Network Settings or Security Groups
Here you change vpc, subnet and security group, and other configurations. I’m leaving this as default.
7. Configure Storage required for your instance
Select the amount of storage you want your instance to have, for the free tier you can choose up to 30 GB of EBS.
Once storage configuration is done, click on launch Instance & initiate the process. After a while, you’ll see your instance running, under EC2 Dashboard > Instances,
As of now we’ve successfully launched the EC2 Instance & is up and running.
8. Accessing your instance
With the EC2 instance now running we need to do some local setup to allow us to connect to the EC2 instance.
Now comes the interesting part, time to run some terminal commands
Right-click on the running instance & click on connect.
Select SSH Client
Open an SSH client on your system
Now locate the private file you’ve created while creating the key pair in Step 5. The key used to launch this instance is “name_of_your_private_file.pem”
Run the below command if necessary, to ensure your key is not publicly viewable. 👇
chmod 400 name_of_your_private_file.pem
Connect to your instance using its Public DNS:
ssh -i "name_of_your_private_file.pem" ec2_username@Public_IPv4_DNS_Address
Conclusion
Setting up an Ubuntu EC2 instance from scratch on AWS is a fun little project. It's relatively easy, and it gives you an opportunity to learn some more about AWS and the command line.