In today’s fast-paced business world, agility and adaptability are not merely desirable traits, they are the requirements for success. This is where AWS EC2 comes in. The EC2 instance is an IaaS model virtual machine that allows you to run any kind of application be it an eCommerce store or a personal blog. It provides you with unparalleled flexibility, scalability, and reliability.
Understanding EC2 Instance
Amazon Elastic Compute Cloud (EC2) instances are foundational building blocks for your cloud infrastructure. It’s the same as the server you use on-premises and your home PC. But instead of physically accessing it you access it using a remote protocol. This gives you full control over the system except for the physical access.
The EC2 instances are elastic as the name indicates and also highly scalable. You can increase and decrease the computing power and other resources as per your requirement at any given time. On top of that AWS provides you with different types of instances that can fulfill all your needs.
Types of EC2 Instances
As of now, AWS provides up to 6 EC2 instance types. Each of them is optimized for a specific project. That includes,
1. General Purpose
These instances are well balanced between compute, memory, and network resources. They are suitable for a wide range of applications, including but not limited to web servers, databases, applications, and more.
2. Compute Optimized
Compute Optimized instances are best for computing power-dependent applications that can utilize high-performance processors. Instances in this category are best suited for batch processing workloads, high-performance web servers, media transcoding machine learning, and more.
3. Memory Optimized
For applications that require a substantial amount of memory this instance type is appropriate. This type excels in tasks like high-performance databases, in-memory casing, and real-time big data analytics.
4. Accelerated Computing
Accelerated computing instances are specialized for workloads that benefit from hardware acceleration. These instances are equipped with powerful processors, and GPUs/TPUs to accelerate tasks like machine learning, code generation, and scientific simulations. They are suitable for businesses looking to harness the immense computational power of specialized hardware.
5. Storage Optimized
These instances are designed for an application that demands high storage, such as file servers, data warehousing, and more. They provide high storage and lower I/O latency. This type of instance is also used in database applications.
6. HPC Optimized
High Performance Computing (HPC) as the name suggests is designed for high-performance computing workloads, such as scientific simulations, data-intensive tasks, weather forecasting, etc. It features powerful CPUs and low-latency high-speed networking.
With all these options it’s hard to not find the best solution for your business needs.
Understanding EC2 Pricing
Aside from the instance type EC2 also provides a flexible pricing model that suits various business needs and budgetary constraints. Understanding EC2 pricing is essential for optimizing costs and making informed decisions.
On-demand
On-demand instances allow you to pay for the computer you use measured in hours. This comes with no upfront cost or any long-term commitments. It’s the best choice to assess the workload of your projects.
Reserved Instances
Reserved Instances (RIs) provide a significant cost-saving opportunity for businesses with predictable workloads. But this comes with a one or three-year commitment for a specific instance type. This can provide you with up to 72% discount for a one or three-year commitment.
Saving Plans
Savings Plans are similar to the Reserved Instance, with this you can get up to 66% for compute saving plans, and up to 72% for EC2 instance saving plans. This also requires a commitment of one or three years.
Spot Instances
Spot Instances are the unused EC2 capacity in the AWS cloud and are available at a discount of up to 90% compared to On-Demand prices. This type of instance should be used for fault-tolerant or stateless workloads.
Get an in-depth guide on saving with AWS : AWS Cost Savings And Pricing Plans
Creating EC2 Instance
To create an EC2 Instance you first have to have an account in AWS. And if you are using an IAM account you will need proper permission to do it. Check Out this article to see how to create an EC2 instance with a free tier account.
Cloud Computing With AWS: Why It’s Important
Here we will create an EC2 instance with an IAM user. To do that, log in to your IAM account. Scroll down the home page and select “Launch a virtual machine” from the Build a Solution section.
This will take you to the EC2 setup page. Choose a name for your Instance.
In the next stage, you will select the Amazon Machine Image (AMI) aka Operating System Image. We’ll select the “Debian” because it comes for free. To find that you will have to click on the arrow until you find it.
However, AWS has more than 1000s of applications and OS images. To look at them you will have to click the “Browse more AMIs” button on the right side.
Once you select the OS, you will need to select the “Instance type”. By default, the “Free tier eligible” instance will be selected. You can click on it to find the instance that best suits your needs. Obviously to do that you will have to know the requirement of CPU and RAM.
We’ll go with the “t2.small” instance that has a $0.023/hour rate for Linux OS. That’s $0.023 x 730 hour = $16.79/month.
If you’d like to see previous generation instances you can just toggle the “All generations” button. And you can also compare instances with “Compare Instance types”.
With “t2.small” as the instance type let’s continue to the “Key pair” section. Amazon’s default security mechanism allows you to select a “Key pair” to log in to your EC2 instance. This thing allows you user how have the private key to connect to the instance. This is mandatory without creating a key pair you won’t be able to create your instance.
You can select an existing key pair or create a new one. Let’s click “Create new key pair” to create a new key pair.
This will pop up a window, give the name of your key pair, select the type, and select the private key format. We prefer you keep the default settings and change the private key type only if you are using putty.
Once you have selected the proper config, click “Create key pair”. This will create a key pair and also download it to your system. Keep the key in a safe place.
The next step is to configure the “Network Settings”. AWS allows you to control the incoming and outgoing traffic using their security group. You can either create a new security group add rules in it or add an existing security group.
Allow SSH will allow you to log in to your instance using SSH. You can either allow all IPs to connect using SSH or only specify the IP you want.
This setting can be changed after you’ve created the machine. So, for now, allow the SSH, and also allow the HTTP, and HTTPS if you will use a web server.
Next, you will have to configure the storage. For this instance, we won’t need more than 8GB of storage. The cost of 8GB storage is 8 GB x $0.08 = $0.64/month.
Unlike compute power the storage is billed monthly not hourly.
You can also add additional storage by clicking on the “Add new volume” button. Let’s keep it to 8 GB and continue.
Then there’s the advanced section that won’t be necessary for now. AWS allows you to create multiple instances at once of the same spec.
You can select the number of instances you want from the “Summary” section. Once everything is set up click the “Launch instance” button.
This will take some time and create the Instance.
Now scroll down the page, and select the “View all instances” button.
This will take you to the EC2 home page. Where you will be able to see all the available instances in your account. This is sensitive to the “Region” you select. E.g. If you created the instance in the “us-east-1” region you won’t see it in the “us-east-2” region.
Connecting with SSH
Amazon provides you with more than one way to connect to your EC2 instance. But the most used and easy way is using the SSH. Select the instance you want to connect and click connect.
From there select “SSH client” and follow the instructions.
Open your terminal and navigate to the directory where you downloaded the PEM file. Execute the first marked command.
Now execute the final command to connect with your EC2 instance.
Now you can do your deployment from here. By default, AWS creates an admin user for you with the sudo permission. And you don’t require any password for sudo. That’s considered not a best security practice. So, you should consider setting up a password for your admin user
Check out this Article on How to secure your EC2 Instance.
Stopping EC2 Instance
To avoid unwanted costs for EC2, it’s recommended to stop the instances that you are not using actively. To do that select the “Instance state” option and select “Stop Instance”.
This will stop the instance (not terminate). So, you can start it again when you need it. And the billing will stop as soon as you stop the instance. This excludes the EBS storage that’s billed monthly. After running this instance for ~11 hours it cost us only $0.25 for the “t2.small” instance.
Conclusions
EC2 is the best solution for your business if you have IT personnel who can utilize the IaaS and deploy your applications properly. However, success depends on proper deployment and monitoring. An unwatched instance may cost you money for a task you didn’t do. That’s why it’s best practice to stop the instance if that’s not being used actively.