Amazon Elastic Compute Cloud (EC2) is one of the most popular AWS services, enabling you to rent virtual servers in the cloud. With EC2, you can deploy applications, host websites, or run simulations without investing in physical hardware.
If you’re new, launching an EC2 instance can seem intimidating. But don’t worry! In this blog, we’ll walk you through the entire process step by step.
Table of Contents
What is Amazon EC2?
Amazon EC2 is a scalable, pay-as-you-go cloud computing service that lets you run virtual machines (VMs), known as instances, in AWS’s secure environment. These instances can be configured to run a variety of operating systems and applications, making them ideal for:
- Hosting websites.
- Running databases.
- Deploying applications.
Step-by-Step Guide to Launch Your First EC2 Instance
Step 1: Log in to the AWS Management Console
- Go to the AWS Management Console.
- Sign in using your AWS account credentials.
Step 2: Navigate to the EC2 Dashboard
- From the console homepage, type EC2 in the search bar and select EC2 from the results.
- This will open the EC2 dashboard, where you can manage instances, security groups, key pairs, and more.
Step 3: Click “Launch Instance”
- In the EC2 dashboard, click on the Launch Instance button.
- This will take you to the configuration wizard for launching an instance.
Step 4: Choose an Amazon Machine Image (AMI)
An AMI is a pre-configured operating system (OS) image. AWS provides several options, including:
- Amazon Linux 2023 (optimized for AWS).
- Ubuntu or Debian for open-source environments.
- Windows Server for Windows-based applications.
For beginners, select the Amazon Linux 2023 Free Tier Eligible AMI.
Step 5: Select an Instance Type
- AWS offers various instance types based on CPU, memory, and storage.
- For Free Tier users, select t2.micro or t4g.micro (750 hours/month for the first 12 months).
- These are ideal for lightweight applications or testing purposes.
Step 6: Configure Instance Details
- Configure the number of instances (start with 1).
- Leave other settings as default for now, such as network, subnet, and auto-assign public IP.
- Enable the Monitoring option if you want detailed metrics in CloudWatch.
Step 7: Add Storage
- By default, EC2 instances come with 8GB of EBS (Elastic Block Store) storage.
- You can increase the storage if needed, but Free Tier covers up to 30GB.
Step 8: Add Tags (Optional)
Tags help organize and identify your resources.
- Click Add Tag and define a key-value pair (e.g., Key: Name, Value: MyFirstInstance).
Step 9: Configure Security Group
- Security groups act as a firewall to control inbound and outbound traffic.
- For this instance:
- Add an inbound rule for SSH (Port 22) to allow access to the server.
- Set the source to My IP to restrict access to your IP address only.
Step 10: Review and Launch
- Review your configuration settings.
- Click Launch and proceed to the key pair creation step.
Step 11: Create or Select a Key Pair
- A key pair is required to securely connect to your instance.
- Choose Create a New Key Pair, give it a name, and download the private key file (.pem).
- Keep this file safe—it’s required to access your instance.
Step 12: Launch Your Instance
- Click the Launch Instances button.
- Wait for a few minutes while AWS initializes your instance.
Step 13: Connect to Your EC2 Instance
Option 1: Using AWS Console
- Go to the Instances page in the EC2 dashboard.
- Select your instance and click Connect.
- Choose Session Manager (if enabled) or follow the instructions for SSH.
Option 2: Using SSH from Your Terminal
- Open a terminal (Linux/Mac) or PowerShell (Windows).
- Navigate to the directory containing your
.pem
key file. - Run the following command:bashCopy code
ssh -i "YourKeyPair.pem" ec2-user@<InstancePublicIP>
Replace<InstancePublicIP>
with the public IP address of your instance (visible in the EC2 dashboard). - Type yes to confirm the connection.
Testing Your Instance
Once connected, you can start using your EC2 instance like a regular Linux server:
- Install software using
yum
,apt
, or other package managers. - Host a web server like Apache or NGINX.
For example, install Apache with the following commands:
bashCopy codesudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
Access your instance’s public IP in a browser to see the default Apache welcome page.
Managing Your EC2 Instance
Start, Stop, or Terminate Instances
- Go to the Instances page in the EC2 dashboard.
- Select your instance and use the Instance State menu to start, stop, or terminate it.
Monitor Performance
- Use CloudWatch to monitor CPU, memory, and network usage.
- Access metrics from the Monitoring tab in the instance details.
Back Up Your Instance
- Create an AMI to save the current state of your instance.
- Go to Actions > Image > Create Image.
Free Tier Considerations
- Stay Within Free Limits
- Free Tier allows 750 hours/month of t2.micro usage.
- Monitor usage in the Billing Dashboard to avoid unexpected charges.
- Shutdown When Not in Use
- Stop or terminate instances you’re not actively using to save hours and costs.
Conclusion
Launching your first EC2 instance is a significant milestone in your AWS journey. With EC2, you can deploy applications, test environments, or host websites in just a few clicks. By following this guide, you’ve taken the first step toward mastering cloud computing with AWS.
Stay tuned for more tutorials, like How to Use S3 for Static Website Hosting or Automating Tasks with AWS Lambda. Keep learning and building!
Learn More:
How to use the AWS - Free Tier?
What is AWS and How does it Work?