How to Launch Your First EC2 Instance on AWS?

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.

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

  1. Go to the AWS Management Console.
  2. Sign in using your AWS account credentials.

Step 2: Navigate to the EC2 Dashboard

  1. From the console homepage, type EC2 in the search bar and select EC2 from the results.
  2. This will open the EC2 dashboard, where you can manage instances, security groups, key pairs, and more.

Step 3: Click “Launch Instance”

  1. In the EC2 dashboard, click on the Launch Instance button.
  2. 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

  1. AWS offers various instance types based on CPU, memory, and storage.
  2. 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

  1. Configure the number of instances (start with 1).
  2. Leave other settings as default for now, such as network, subnet, and auto-assign public IP.
  3. Enable the Monitoring option if you want detailed metrics in CloudWatch.

Step 7: Add Storage

  1. By default, EC2 instances come with 8GB of EBS (Elastic Block Store) storage.
  2. 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.

  1. Click Add Tag and define a key-value pair (e.g., Key: Name, Value: MyFirstInstance).

Step 9: Configure Security Group

  1. Security groups act as a firewall to control inbound and outbound traffic.
  2. 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

  1. Review your configuration settings.
  2. Click Launch and proceed to the key pair creation step.

Step 11: Create or Select a Key Pair

  1. A key pair is required to securely connect to your instance.
  2. 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

  1. Click the Launch Instances button.
  2. Wait for a few minutes while AWS initializes your instance.

Step 13: Connect to Your EC2 Instance

Option 1: Using AWS Console

  1. Go to the Instances page in the EC2 dashboard.
  2. Select your instance and click Connect.
  3. Choose Session Manager (if enabled) or follow the instructions for SSH.

Option 2: Using SSH from Your Terminal

  1. Open a terminal (Linux/Mac) or PowerShell (Windows).
  2. Navigate to the directory containing your .pem key file.
  3. Run the following command:bashCopy codessh -i "YourKeyPair.pem" ec2-user@<InstancePublicIP> Replace <InstancePublicIP> with the public IP address of your instance (visible in the EC2 dashboard).
  4. 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

  1. Go to the Instances page in the EC2 dashboard.
  2. Select your instance and use the Instance State menu to start, stop, or terminate it.

Monitor Performance

  1. Use CloudWatch to monitor CPU, memory, and network usage.
  2. Access metrics from the Monitoring tab in the instance details.

Back Up Your Instance

  1. Create an AMI to save the current state of your instance.
  2. Go to Actions > Image > Create Image.

Free Tier Considerations

  1. Stay Within Free Limits
    • Free Tier allows 750 hours/month of t2.micro usage.
    • Monitor usage in the Billing Dashboard to avoid unexpected charges.
  2. 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?

Leave a Comment