Exploring Amazon Elastic Compute Cloud (Amazon EC2) and Instance Types
Table of contents
- What is Amazon EC2?
- Launch EC2 instance
- Step 1: Sign in to the AWS Management Console
- Step 2: Access the EC2 Dashboard
- Step 3: Launch an Instance
- Step 4: Choose an Amazon Machine Image (AMI) and give name to your server
- EC2 Instance Types
- Choosing the Right Instance Type
- Step 5: Select Key Pair
- Step 6: Configure Security Group
- Step 7: Add Storage
- Step 8: Configure Instance Details with User Data
- Step 9: View Instances
- Step 10: Checking the Script Running
- Conclusion
Amazon Elastic Compute Cloud (Amazon EC2) is a fundamental component of Amazon Web Services (AWS) that provides scalable computing capacity in the cloud.
Amazon EC2 lets users launch virtual servers, called instances, which can be customized to fit specific needs. This flexibility makes EC2 an ideal choice for a wide range of applications, from simple web hosting to complex data processing tasks. In this article, we'll dive into the essentials of Amazon EC2 and explore the various instance types available.
What is Amazon EC2?
Amazon EC2 offers resizable compute capacity, which allows businesses to easily scale their infrastructure up or down based on demand. This elasticity helps in managing workloads efficiently without the need for large upfront investments in hardware.
Key Features of Amazon EC2
Scalability: Automatically scale your applications based on demand with Auto Scaling.
Flexibility: Choose from a wide variety of instance types optimized for different use cases.
Cost-Effective: Pay only for the compute capacity you use, with various pricing models like On-Demand, Reserved Instances, and Spot Instances.
Secure: Leverage AWS security features such as Virtual Private Cloud (VPC), security groups, and IAM roles to secure your instances.
Reliability: Benefit from AWS's global infrastructure and data centers designed for high availability.
Launch EC2 instance
Create your EC2 resources and launch your EC2 instance:
Follow these simple steps for launching an EC2 instance in the free tier service:
Step 1: Sign in to the AWS Management Console
Navigate to the AWS Management Console.
Sign in with your AWS account credentials.
Step 2: Access the EC2 Dashboard
In the AWS Management Console, find the "Services" dropdown in the top left corner.
Under "Compute," select "EC2" to access the EC2 Dashboard.
Step 3: Launch an Instance
In the EC2 Dashboard, click the "Launch Instance" button.
Step 4: Choose an Amazon Machine Image (AMI) and give name to your server
Give name to your server , for example: TestServer
Select an AMI, a pre-configured template for your virtual machine.
Click the "Next: Configure Instance Details" button.
EC2 Instance Types
Amazon EC2 instances come in various types, each optimized for different tasks. The instance types are grouped into families based on their use cases:
General Purpose: Balanced instances for a variety of workloads.
These instances provide a balance of compute, memory, and networking resources, making them suitable for a variety of applications. Popular general-purpose instances include:
t3, t3a: Burstable performance instances ideal for applications with variable workloads.
m5, m5a, m6g: Versatile instances for databases, enterprise applications, and caching.
Compute Optimized: Ideal for compute-intensive tasks.
Compute-optimized instances are designed for applications that require high compute performance. Examples include:
- c5, c5a, c6g: Instances for high-performance computing, batch processing, and media transcoding.
Memory Optimized: Suitable for memory-intensive applications.
Memory-optimized instances are intended for memory-intensive applications. These include:
r5, r5a, r6g: Instances for large databases, in-memory caches, and real-time big data processing.
x1e, x2gd: Instances with high memory for SAP HANA, Apache Spark, and other big data analytics workloads.
Storage Optimized: Designed for workloads requiring high, sequential read and write access to large data sets.
These instances are designed for applications requiring high, sequential read and write access to large datasets. Examples include:
i3, i3en: Instances for high I/O operations, suitable for NoSQL databases and data warehousing.
d2, d3: Instances for distributed file systems and data warehousing applications.
Accelerated Computing: Instances with hardware accelerators for intensive graphics or parallel processing.
Accelerated computing instances use hardware accelerators, or co-processors, to perform functions such as floating-point number calculations, graphics processing, or data pattern matching more efficiently than software running on a general-purpose CPU. Examples include:
p3, p4: GPU instances for machine learning, high-performance computing, and graphics rendering.
f1: FPGA instances for custom hardware accelerations.
Choosing the Right Instance Type
Selecting the appropriate instance type depends on your specific use case and performance requirements. Here are a few tips to help you choose the right instance type:
Evaluate Workload Requirements: Determine whether your application is compute-intensive, memory-intensive, or storage-intensive.
Consider Cost: Choose instances that provide the best price-to-performance ratio for your workload.
Benchmarking: Run performance tests to compare different instance types.
Scaling Needs: Consider the scalability of your application and choose instances that can easily scale up or down based on demand.
Step 5: Select Key Pair
Choose an existing key pair or create a new one for secure instance access.
Acknowledge that you have access to the selected key pair.
Step 6: Configure Security Group
Configure security groups to control inbound and outbound traffic.
Step 7: Add Storage
Specify the storage requirements for your instance, configuring the root volume and additional volumes as needed.
Click the "Next: Add Tags" button.
Step 8: Configure Instance Details with User Data
Scroll down to the "Advanced Details."
In the "User data" field, enter initialization scripts or commands for custom configuration during instance launch.
Let's write a Bash script that sets up an Apache HTTP server on a Linux system, specifically on a CentOS or RHEL-based distribution.
#!/bin/bash sudo su yum update -y yum install httpd -y echo "<html><h1>Hello Welcome to TestServer</h1><html>" > /var/www/html/index.html systemctl start httpd systemctl enable httpd exit
Let's break down the code:
Line 1:
#!/bin/bash
This is the shebang line, which specifies the interpreter that should be used to run the script. In this case, it's Bash (Bourne-Again SHell).
The
#
symbol is a comment character in Bash, but when it's followed by an exclamation mark (!
), it's treated as a special directive.
Line 2: sudo su
sudo
is a command that allows a user to run a command with elevated privileges (i.e., as the root user).su
is a command that switches the user to the root user.By combining
sudo
andsu
, the script gains root access. This is necessary because the subsequent commands require root privileges.
Line 3: yum update -y
yum
is the package manager for CentOS/RHEL-based systems.update
is a command that updates the package list and installs any available updates.The
-y
flag automatically answers "yes" to any prompts, allowing the update to proceed without user intervention.
Line 4: yum install httpd -y
This line installs the Apache HTTP server package (
httpd
) usingyum
.Again, the
-y
flag is used to automatically answer "yes" to any prompts.
Line 5: echo "<html><h1>Hello Welcome to TestServer</h1><html>" > /var/www/html/index.html
echo
is a command that outputs its arguments to the console.The string
<html><h1>Hello Welcome to TestServer</h1><html>
is the content of the HTML page.The
>
symbol redirects the output of theecho
command to a file namedindex.html
in the/var/www/html/
directory.This directory is the default document root for Apache on CentOS/RHEL-based systems.
Line 6: systemctl start httpd
systemctl
is the service manager for CentOS/RHEL-based systems.start
is a command that starts the specified service (in this case,httpd
).
Line 7: systemctl enable httpd
- This line enables the
httpd
service to start automatically on boot.
Line 8: exit
- This line exits the script.
What the script does:
Gains root access using
sudo su
.Updates the package list and installs any available updates using
yum update -y
.Installs the Apache HTTP server package using
yum install httpd -y
.Creates a simple HTML page in the default document root directory using
echo
.Starts the Apache HTTP server service using
systemctl start httpd
.Enables the Apache HTTP server service to start automatically on boot using
systemctl enable httpd
.Exits the script.
- Click the "Launch Instances" button.
Step 9: View Instances
Once launched, view your instances on the EC2 Dashboard.
Wait for the instance status to change to "running" before connecting to it.
Step 10: Checking the Script Running
After launching the instances, it is crucial to verify that the script has executed correctly and that all services are running as expected.
Check the public IPv4 address to see the page hosted by the script running.
Note: This will run in http://54.166.195.148/ (Not Secure)
Conclusion
Amazon EC2 offers various instance types to meet different application needs. Understanding these types helps you choose the best instances for optimal performance and cost-efficiency. Whether for a simple web app or a complex machine learning model, EC2 provides the flexibility and scalability needed. With its robust features and global reach, EC2 is a top choice for businesses using cloud computing to drive innovation and efficiency. Exploring EC2 instance types helps you make informed decisions to best use AWS's powerful cloud platform.
Subscribe to my newsletter
Read articles from Jasai Hansda directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Jasai Hansda
Jasai Hansda
Software Engineer (2 years) | In-transition to DevOps. Passionate about building and deploying software efficiently. Eager to leverage my development background in the DevOps and cloud computing world. Open to new opportunities!