DEV Community

Cover image for How to Create an EC2 Instance on AWS
Chidi
Chidi

Posted on • Edited on

How to Create an EC2 Instance on AWS

Step-by-Step Guide on How to Create an EC2 Instance on AWS

Amazon Elastic Compute Cloud (EC2) is one of AWS’s most popular services, that lets you launch and manage virtual servers in the cloud. Whether you're hosting a website, running a database, or testing software, EC2 provides scalable, secure, and customizable computing capacity.

This guide walks you through creating a basic EC2 instance using the AWS Management Console.


Prerequisites

  • An AWS account (sign up if you don’t have one)
  • Basic familiarity with cloud concepts
  • (Optional) SSH key pair for secure remote access

Step 1: Sign in to the AWS Management Console

  1. Go to https://console.aws.amazon.com.
  2. Sign in with your AWS credentials.

Step 2: Navigate to the EC2 Dashboard

  1. In the AWS Console, search for EC2.
  2. Click EC2 to open the EC2 Dashboard.  Navigate to the EC2 Dashboard ---

Step 3: Launch an Instance

  1. Click Instances in the left navigation pane.
  2. Click the Launch Instance button.  Launch an Instance

Step 4: Configure Instance Basics

On the Launch an Instance page:

  • Name: Enter a name for your instance (e.g., MyFirstInstance).
  • Application and OS Images (AMI): Choose an Amazon Machine Image (AMI). For beginners, the Amazon Linux 2023 AMI (Free Tier eligible) is a good choice. Note: If you need Windows or another OS, select the corresponding AMI.
  • Instance Type: Choose the instance type (e.g., t2.micro for Free Tier eligibility). Configure Instance Basics ---

Step 5: Create or Choose a Key Pair

  • In Key pair (login), choose an existing key pair or create a new one.
  • To create a new one:
    1. Click Create new key pair.
    2. Enter a name.
    3. Choose the format (e.g., .pem for Linux/Unix).
    4. Download it securely.

Important: Keep this file safe. You’ll need it to SSH into your instance.

Create or Choose a Key Pair

Step 6: Configure Network Settings

  • AWS will auto-select a VPC and subnet by default.
  • Under Firewall (security groups):
    • Create a new security group or choose an existing one.
    • For SSH access, add a rule:
    • Type: SSH
    • Port: 22
    • Source: Anywhere (0.0.0.0/0) or My IP (more secure).

⚠️ Warning: Opening SSH to “Anywhere” is less secure. Restrict it to your IP whenever possible.

Best Practice: Avoid 0.0.0.0/0 for production. Always limit to trusted IP addresses.

Configure Network Settings

Step 7: Add Storage

  • The default root volume is usually sufficient (e.g., 8 GiB gp2).
  • You can increase the size or add additional volumes if needed.

Add Storage

Step 8: Review and Launch

  • Review your instance configuration.
  • Click Launch Instance.

Review and Launch

Step 9: View and Connect to Your Instance

  • Click View Instances after launching.
  • Wait until Instance State shows running.
  • Note the Public IPv4 address of your instance.

View and Connect to Your Instance 1

View and Connect to Your Instance 2

Step 10: Connect to Your Instance via SSH

Connect to Your Instance

Open your terminal and run:

Set the correct permissions on your key

chmod 400 /path/to/your-key.pem
Enter fullscreen mode Exit fullscreen mode

Note: SSH username varies by AMI:

  • Amazon Linux: ec2-user
  • Ubuntu: ubuntu
  • Other distributions: Check AWS documentation for the correct username.

Example SSH Command

ssh -i /path/to/your-key.pem <your-user-name>@<your-ip>
Enter fullscreen mode Exit fullscreen mode

🎉 Congratulations! You’ve launched your first EC2 instance and connected via SSH. You can now deploy applications, host websites, or explore AWS features.

Top comments (0)