How to Create the EC2 Instance: A Step-by-Step Guide
Amazon Elastic Compute Cloud (EC2) is one of the core
services offered by AWS, allowing users to create and manage virtual servers in
the cloud. EC2 instances provide scalable computing capacity, making them ideal
for hosting applications, running test environments, or performing data
analysis. This guide will walk you through how to create the EC2 instance
step-by-step.
Prerequisites
Before you start, ensure you have the following:
- An
AWS account: If you don’t already have one, sign up at aws.amazon.com.
- Basic
understanding of AWS services: Familiarity with the AWS Management
Console is helpful.
- Billing
information configured: Setting up EC2 instances incurs costs based on
usage, so ensure your billing details are accurate.
Step 1: Log in to the AWS Management Console -> Steps to Create an AWS Account
- Go
to AWS Management Console.
- Enter
your login credentials and click Sign In.
- Navigate
to the EC2 service by typing “EC2” in the search bar and selecting EC2
from the results.
Step 2: Launch an EC2 Instance
- In
the EC2 dashboard, click on the Launch Instance button.
- You
will be taken to the instance creation wizard.
Step 3: Choose an Amazon Machine Image (AMI)
The AMI determines the operating system and software
pre-installed on the instance.
- Browse
the list of available AMIs and select one. Common options include:
- Amazon
Linux (Free-tier eligible)
- Ubuntu
Server
- Microsoft
Windows Server
- Red
Hat Enterprise Linux
- For
this guide, we’ll use Amazon Linux 2023 (Free-tier eligible).
Step 4: Select the Instance Type
Instance types define the hardware configuration, including
CPU, memory, and networking capacity.
- Choose
an instance type that suits your needs. For beginners or low-demand
workloads, select t2.micro (free-tier eligible).
- Click
Next: Configure Instance Details.
Step 5: Configure Instance Details
Here, you can customize your instance settings:
- Number
of Instances: Default is 1.
- Network:
Select the default VPC or a custom VPC if you have one.
- Subnet:
Choose the subnet where the instance will reside.
- Auto-assign
Public IP: Set this to Enable if you want your instance to have
a public IP address.
- IAM
Role: Assign an IAM role to the instance for secure access to AWS
services. For example, if you plan to use AWS Session Manager, ensure the
IAM role has the AmazonSSMManagedInstanceCore policy attached.
- Advanced
Settings: You can configure shutdown behavior, instance metadata
options, and more.
- Click
Next: Add Storage.
Step 6: Add Storage
Define the storage requirements for your instance.
- The
default size is 8 GiB for general-purpose (gp2) volumes. Adjust this based
on your needs.
- Click
Add New Volume if additional storage is required.
- Click
Next: Add Tags.
Step 7: Add Tags
Tags help organize your AWS resources.
- Click
Add Tag.
- Enter
a key-value pair, such as:
- Key:
Name
- Value:
MyEC2Instance
- Click
Next: Configure Security Group.
Step 8: Configure Security Group
Security groups act as virtual firewalls, controlling
inbound and outbound traffic.
- Select
Create a new security group.
- Add
rules for required protocols:
- Type:
SSH
- Protocol:
TCP
- Port
Range: 22
- Source:
My IP (to restrict access to your IP address only)
- Click
Review and Launch.
Step 9: Review and Launch
- Review
all the settings and ensure they match your requirements.
- Click
Launch.
- A
pop-up will prompt you to create or use an existing key pair. Key pairs
are used to securely access your instance.
- Create
a new key pair: Download the .pem file and keep it secure.
- Use
an existing key pair: Select one if you have it.
- Check
the acknowledgment box and click Launch Instances.
Step 10: Connect to Your EC2 Instance
After launching, you can connect to your instance.
- In
the EC2 dashboard, click Instances on the left menu.
- Locate
your instance and note its Public IPv4 Address.
- Open
a terminal (Linux/Mac) or PuTTY (Windows) and run the SSH command:
ssh -i /path/to/your-key.pem ec2-user@your-public-ip
- Replace
/path/to/your-key.pem with the path to your downloaded key file and your-public-ip
with the instance’s public IP address.
Step 11: Access EC2 via AWS Session Manager
AWS Session Manager allows you to connect to your EC2
instance without using SSH or a public IP.
- Ensure
the instance has an IAM role with the AmazonSSMManagedInstanceCore policy.
- Install
and configure the SSM Agent if it’s not already installed. (Amazon Linux
and Ubuntu usually come with it pre-installed.)
- In
the AWS Management Console, go to Session Manager under the Systems
Manager service.
- Click
Start Session, select your instance, and click Start Session
to open a terminal in your browser.
This approach enhances security by eliminating the need for
open SSH ports and public IP addresses.
Common Use Cases for EC2 Instances
Understanding the practical applications of EC2 instances
can help you better leverage their capabilities. Here are some common use
cases:
- Web
Hosting: Deploy websites and web applications with ease, scaling
resources based on traffic.
- Application
Development and Testing: Use EC2 for staging and testing environments
to ensure high-quality application deployment.
- Big
Data Processing: Run data analytics workloads using distributed
computing frameworks like Hadoop or Spark.
- Machine
Learning: Train and deploy machine learning models on EC2 instances
with high-performance GPUs.
- Disaster
Recovery: Implement failover mechanisms and backups to ensure business
continuity during disruptions.
Tips for Managing EC2 Instances
- Monitor
Usage: Use CloudWatch to track resource utilization and set alarms for
cost control.
- Terminate
Unused Instances: Stop or terminate instances when not in use to avoid
unnecessary costs.
- Optimize
Costs: Use spot instances or reserved instances for predictable
workloads to reduce costs.
- Security
Best Practices:
- Regularly
update your instance’s operating system and applications.
- Use
IAM roles instead of hardcoding credentials.
- Enable
encryption for sensitive data.
Conclusion
Learning how to create the EC2 instance is an
essential skill for anyone working with AWS. This step-by-step guide provides
all the details needed to set up your virtual server effectively. Whether
you’re a developer, sysadmin, or cloud enthusiast, EC2’s flexibility and
scalability make it a powerful tool for a variety of tasks.
Remember to explore advanced features such as auto-scaling
groups, Elastic Load Balancers, and AWS Systems Manager for managing multiple
instances efficiently. With consistent practice, you’ll master EC2 and harness
its full potential to meet your business or personal needs.
0 Comments