Hakia LogoHAKIA.com

How to Set Up Your First AWS EC2 Instance Step-by-Step

Author

Taylor

Date Published

Categories

Conceptual image of AWS cloud console interface for setting up an EC2 instance.

Setting Up Your First AWS EC2 Instance: A Step-by-Step Guide

Amazon Web Services (AWS) offers a wide range of cloud computing services, and one of the most fundamental is Amazon Elastic Compute Cloud, better known as EC2. EC2 provides virtual servers, called instances, that allow you to run applications in the cloud. Think of it like renting a computer in AWS's data center that you can configure and control remotely. Setting up your first EC2 instance might seem complex, but this guide will walk you through the process step-by-step. We'll cover everything from logging in to launching and connecting to your new virtual server.

For beginners, AWS offers a Free Tier, which often includes enough hours of a basic EC2 instance type (like t2.micro or t3.micro) to complete this tutorial without incurring charges, provided your account is less than 12 months old and you haven't exceeded the limits. This makes it easy to experiment and learn.

Prerequisites: Your AWS Account

Before you can launch an EC2 instance, you need an AWS account. If you don't have one, you'll need to sign up on the AWS website. The signup process involves providing contact information and payment details (though you won't necessarily be charged if you stay within Free Tier limits). Once your account is set up, you can log in to the AWS Management Console.

Step 1: Navigate to the EC2 Dashboard

Once logged into the AWS Management Console:

  1. Select the AWS Region: In the top-right corner of the console, you'll see a dropdown menu showing the current AWS Region (e.g., "Ohio" or "us-east-2"). It's generally a good idea to choose a region geographically close to you or your users to minimize latency. For this first instance, any region will work, but remember which one you choose.
  2. Find the EC2 Service: You can either type "EC2" into the main search bar at the top or click on "Services" in the top-left menu and find EC2 under the "Compute" category.
  3. Access the Dashboard: Clicking on EC2 will take you to the EC2 Dashboard, which provides an overview of your EC2 resources in the selected region.

Step 2: Launching Your Instance

From the EC2 Dashboard, find the "Launch instance" button (it might be in a box labeled "Launch instance" or near the top) and click it. This starts the configuration wizard.

Name Your Instance: The first field asks for a Name for your instance. Give it something descriptive, like "MyFirstWebServer" or "TestLinuxInstance". This name tag helps you identify the instance later.

Step 3: Choosing an Amazon Machine Image (AMI)

Next, under "Application and OS Images (Amazon Machine Image)", you need to select an AMI. An AMI is a template containing the software configuration (operating system, application server, and applications) required to launch your instance. Think of it as the blueprint for your server's software.

AWS offers many AMIs, including various Linux distributions (like Amazon Linux, Ubuntu, CentOS) and Windows Server versions. For your first instance, especially if using the Free Tier:

  • Look for the "Quick Start" section.
  • Select an AMI marked "Free tier eligible". A common recommendation is "Amazon Linux 2 AMI" or the latest Amazon Linux version.

Step 4: Selecting an Instance Type

Under "Instance type", you choose the hardware specifications for your instance – CPU, memory, storage, and networking capacity. AWS offers a vast array of instance types optimized for different tasks (general purpose, compute-optimized, memory-optimized, etc.).

For your first instance and to stay within the Free Tier, select `t2.micro` (or `t3.micro` if t2 is unavailable in your chosen region). These are general-purpose instances suitable for basic tasks and testing. Make sure the one you select is marked "Free tier eligible".

Step 5: Configuring Key Pairs for Secure Access

The "Key pair (login)" section is crucial for security. A key pair consists of a public key that AWS stores on the instance and a private key file that you store securely on your computer. You use the private key to prove your identity when connecting to the instance via SSH (for Linux) or RDP (for Windows).

  • If you have an existing key pair you want to use, select it from the dropdown.
  • For your first time, click "Create new key pair".
  • Enter a name for the key pair (e.g., "my-aws-key").
  • Choose the key pair type (RSA is common) and the private key file format. .pem is needed for OpenSSH on Linux/macOS, while .ppk is for PuTTY on Windows.
  • Click "Create key pair". Your browser will automatically download the private key file (e.g., my-aws-key.pem).

Important: Save this downloaded file in a secure and memorable location. You cannot download it again. If you lose it, you will lose access to your instance (unless you've set up alternative access methods). Do not choose "Proceed without a key pair" unless you have a specific reason and know how you will connect, as the standard connection methods described here require it.

Step 6: Configuring Network Settings

The "Network settings" section defines how your instance connects to the internet and what traffic is allowed.

  • VPC (Virtual Private Cloud): This is your private network space within AWS. For beginners, using the default VPC provided in your account is usually sufficient.
  • Subnet: Within the VPC, subnets define ranges of IP addresses. You can usually leave this as "No preference" to let AWS choose a default subnet in an Availability Zone.
  • Auto-assign Public IP: Ensure this is set to "Enable" so your instance gets a public IP address, allowing you to connect to it from the internet.
  • Firewall (Security Groups): Security groups act as virtual firewalls, controlling inbound and outbound traffic. You can either create a new security group or select an existing one.

By default, if you choose "Create security group", AWS often suggests rules based on the AMI you selected:

  • For Linux AMIs: It typically allows SSH traffic (port 22).
  • For Windows AMIs: It typically allows RDP traffic (port 3389).

Pay attention to the "Source type". The default might be "Anywhere" (0.0.0.0/0 for IPv4), which allows connections from any IP address. While convenient for initial setup, this is insecure for production environments. Ideally, you should restrict the source to "My IP" (AWS will auto-detect your current public IP) or a specific range of IP addresses you trust. For this first test, you can leave it as "Anywhere" but remember to tighten this later if the instance becomes important.

Step 7: Configuring Storage

Under "Configure storage", you define the disk volumes attached to your instance. Every instance needs a root volume, which is where the operating system is installed. This is usually an EBS (Elastic Block Store) volume.

The default settings usually provide a small root volume (e.g., 8 GB or 30 GB). If you're eligible for the Free Tier, you can get up to 30 GB of General Purpose SSD (gp2 or gp3) EBS storage. The default size is often sufficient for basic testing. You can add more volumes later if needed for data storage.

Step 8: Review and Launch

The "Summary" panel on the right side shows a recap of your configuration (AMI, instance type, security group, storage). Review these settings carefully. Ensure your instance type and storage are Free Tier eligible if that's your goal.

When you're ready, click the "Launch instance" button.

You'll see a success screen, indicating that your instance is launching. You can click on the instance ID link provided on this screen to go directly to the "Instances" page and monitor its status. Initially, the "Instance state" will be "pending". After a minute or two, it should change to "running", and the "Status check" should eventually show "2/2 checks passed". Your instance is now ready!

Step 9: Connecting to Your Instance

Now that your instance is running, you need to connect to it. The method depends on the operating system (AMI) you chose.

Connecting to a Linux Instance (via SSH):

  1. Select your instance in the EC2 console.
  2. Find the "Public IPv4 address" or "Public IPv4 DNS" in the details pane below. You'll need one of these.
  3. Open a terminal (on Linux or macOS) or an SSH client like PuTTY or Windows Terminal with SSH (on Windows).
  4. Navigate to the directory where you saved your private key file (.pem).
  5. (Linux/macOS only) Ensure your key file has the correct permissions. Run: chmod 400 your-key-name.pem
  6. Use the SSH command. The format is generally: ssh -i your-key-name.pem user_name@instance_public_dns_or_ip

Replace your-key-name.pem with the actual filename.

Replace user_name with the default username for the AMI. For Amazon Linux, it's ec2-user. For Ubuntu, it's ubuntu.

Replace instance_public_dns_or_ip with the Public IPv4 address or DNS name you noted earlier.

  1. The first time you connect, you'll likely see a message about the authenticity of the host. Type "yes" and press Enter to continue.
  2. You should now be logged into your EC2 instance's command line.

Connecting to a Windows Instance (via RDP):

  1. Select your instance in the EC2 console and click the "Connect" button near the top.
  2. Go to the "RDP client" tab.
  3. Click "Get password". You'll need to upload the private key file (.pem) you downloaded earlier.
  4. Click "Decrypt Password". AWS will display the initial Administrator password. Copy this password and store it securely.
  5. Click "Download remote desktop file". This downloads a .rdp file configured with your instance's connection details.
  6. Open the downloaded .rdp file. This will launch the Remote Desktop Connection client.
  7. Click "Connect". You may see warnings about the publisher or certificate; you can usually proceed.
  8. When prompted, enter the password you decrypted earlier. The default username is typically "Administrator" (check the console connection page if unsure, as it can vary by OS language).
  9. You should now see the Windows desktop of your EC2 instance.

Step 10: Cleaning Up - Terminating Your Instance

Once you're finished experimenting with your instance, it's essential to clean up to avoid unexpected charges, especially if you go beyond the Free Tier limits or keep the instance running long-term.

You have two main options:

  • Stop: Shuts down the instance but keeps the root EBS volume. You won't be charged for instance usage while it's stopped, but you will still be charged for the EBS volume storage. You can easily restart a stopped instance later.
  • Terminate: Permanently deletes the instance and, by default, its root EBS volume. You cannot recover a terminated instance. This stops all charges associated with the instance and its root volume.

To terminate your instance:

  1. Go back to the EC2 Instances page in the AWS Console.
  2. Select the checkbox next to the instance you want to terminate.
  3. Click the "Instance state" dropdown menu.
  4. Choose "Terminate instance".
  5. Confirm the termination in the pop-up window by clicking "Terminate".

The instance state will change to "shutting-down" and then "terminated". It might remain visible in the console for a short time before disappearing.

Where to Go From Here

Congratulations! You've successfully launched, connected to, and terminated your first AWS EC2 instance. This is just the beginning of what you can do with AWS compute services. From here, you could explore:

  • Installing Software: Install a web server (like Apache or Nginx), a database, or your own application on the instance.
  • Adding Storage: Learn how to attach additional EBS volumes for persistent data storage.
  • Security Groups: Experiment with modifying security group rules to allow different types of traffic (e.g., HTTP/HTTPS for a web server).
  • Elastic IPs: Understand how to allocate a static public IP address that doesn't change when you stop/start the instance.
  • Monitoring: Use AWS CloudWatch to monitor your instance's performance (CPU usage, network traffic, etc.).

For more detailed information and advanced options, the official AWS documentation is an excellent resource. You can find the official Get started with Amazon EC2 User Guide helpful, along with the Getting Started with Amazon EC2 page which offers tutorials and links to further resources. Additionally, many online tutorials, like this guide on creating an EC2 instance, provide different perspectives.

For more insights on cloud computing and related technologies, you might explore resources like those found on platforms dedicated to technical knowledge sharing. You can also find other helpful guides in our cloud services section.

Sources

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html

https://aws.amazon.com/ec2/getting-started/

https://www.geeksforgeeks.org/amazon-ec2-creating-an-elastic-cloud-compute-instance/

Abstract digital graphic representing cloud computing, networks, and data relevant to AWS services.
AWS

Explore what Amazon Web Services (AWS) is, the core concepts of cloud computing, and understand the key reasons why businesses and individuals should pay attention to this dominant cloud platform.

Abstract visualization of cloud computing costs showing charts, graphs, and currency symbols.
AWS

Understand the real costs of using Amazon Web Services (AWS). Explore pay-as-you-go models, commitment discounts, free tiers, support plans, and cost factors for popular services.