AWS EC2 Launch Tutorial for Absolute Beginners
This guide provides a foundational understanding and step-by-step instructions for launching your first Amazon EC2 instance. We will focus on best…
This guide provides a foundational understanding and step-by-step instructions for launching your first Amazon EC2 instance. We will focus on best practices for beginners, ensuring a secure and functional virtual server ready for your applications.
Understanding Core EC2 Concepts
Before diving into the console, it's crucial to grasp the fundamental components that make up an EC2 instance and its surrounding environment:
- Amazon Machine Image (AMI): A template that contains a software configuration (operating system, application server, applications). You select an AMI when launching an instance. Examples include Amazon Linux, Ubuntu, Windows Server.
- Instance Type: Defines the virtual hardware for your instance, including CPU, memory, storage (local instance store), and network performance. Instance types are named like
t2.micro,m5.large, etc., where the first letter denotes the family (e.g., T for burstable performance, M for general purpose) and the number indicates the generation. - Key Pair: A set of security credentials used to prove your identity when connecting to an instance. It consists of a public key (stored by AWS) and a private key (stored by you). For Linux instances, SSH uses this key pair.
- Security Group: Acts as a virtual firewall for your instance to control inbound and outbound traffic. You define rules that specify allowed protocols, port ranges, and source/destination IP addresses.
- Elastic IP (EIP): A static public IPv4 address designed for dynamic cloud computing. Unlike the default public IP assigned to an instance (which changes upon stop/start), an EIP remains associated with your AWS account until explicitly released, allowing you to remap it to different instances.
- Amazon EBS (Elastic Block Store): Persistent block storage volumes that can be attached to EC2 instances. EBS volumes remain independent of the instance's lifecycle, meaning data persists even if the instance is terminated.
Launching Your First EC2 Instance (Step-by-Step)
Follow these steps to launch a free-tier eligible Amazon Linux 2023 instance:
1. Sign In to the AWS Management Console
Navigate to aws.amazon.com and sign in to your account. If you don't have one, create a new AWS account. Be sure to select a region close to your geographical location for lower latency (e.g., N. Virginia, Ohio, Ireland).
2. Navigate to the EC2 Dashboard
Once logged in, type "EC2" into the search bar at the top of the console and select "EC2" from the services list. This will take you to the EC2 Dashboard.
3. Initiate Instance Launch
On the EC2 Dashboard, click the prominent "Launch instance" button (or "Launch instances" on the newer console design).
4. Choose an AMI (Amazon Machine Image)
In the "Name and tags" section, give your instance a meaningful name, e.g., MyWebServer. Scroll down to "Application and OS Images (Amazon Machine Image)".
- Search for
Amazon Linux. - Select "Amazon Linux 2023 AMI" (HVM, kernel 6.1, x86_64). This is a free-tier eligible option.
5. Choose an Instance Type
Under "Instance type", select t2.micro. This is also free-tier eligible and provides sufficient resources for basic testing and learning.
- CPU: 1 vCPU
- Memory: 1 GiB
- EBS Optimized: No
- Network Performance: Low to Moderate
6. Create a New Key Pair
Under "Key pair (login)", click "Create new key pair".
- Key pair name: Provide a unique name, e.g.,
my-ec2-key. - Key pair type: RSA (default).
- Private key file format:
.pem(for OpenSSH users on Linux/macOS) or.ppk(for PuTTY on Windows). Choose.pemfor this tutorial. - Click "Create key pair". Your browser will download the
.pemfile. Store this file securely; you cannot download it again.
7. Configure Network Settings (Security Group)
Under "Network settings", click "Edit".
- Security group name:
my-ssh-security-group(or similar). - Description:
Allow SSH access to my instance. - Inbound security group rules:
- By default, a rule for SSH (port 22) is usually pre-configured.
- For "Source type", select "My IP" to restrict SSH access to your current public IP address only. This is a crucial security best practice for beginners. If your IP changes, you'll need to update this rule. For broader access (not recommended for production), you could select "Anywhere".
- If you plan to host a web server (HTTP/HTTPS), you would add additional rules here for port 80 (HTTP) and/or port 443 (HTTPS), with source "Anywhere" for public access. For this tutorial, only SSH is necessary.
8. Configure Storage
Under "Configure storage", the default 8 GiB General Purpose SSD (gp2) volume is sufficient and free-tier eligible. You can increase this if needed, but be mindful of free-tier limits (30 GiB of EBS GP2 per month).
9. Review and Launch
Review all your configurations in the "Summary" panel on the right. Ensure everything looks correct, especially the AMI, instance type, key pair, and security group rules.
Click "Launch instance".
10. View Instance Status
After a few moments, you'll see a "Launch Status" page. Click "View all instances". Your new instance will be in a "pending" state. Wait until its "Instance state" changes to "running" and the "Status checks" show "2/2 checks passed". This usually takes 1-2 minutes.
Connecting to Your EC2 Instance via SSH
Once your instance is running, you can connect to it using SSH.
1. Locate Instance Public IP/DNS
From the EC2 Instances page, select your running instance. In the "Details" tab below, find the "Public IPv4 address" (e.g., 54.XXX.YYY.ZZZ) or "Public IPv4 DNS" (e.g., ec2-54-XXX-YYY-ZZZ.compute-1.amazonaws.com).
2. Prepare Your Key Pair
On your local machine, open a terminal (Linux/macOS) or Git Bash/WSL (Windows).
- Navigate to the directory where you downloaded your
.pemfile. - Change the permissions of your private key file to ensure it's not publicly viewable (a security requirement for SSH):
chmod 400 my-ec2-key.pem
3. Connect Using SSH
Use the ssh command with your private key, the default user for Amazon Linux (ec2-user), and the instance's public IP or DNS:
ssh -i my-ec2-key.pem ec2-user@54.XXX.YYY.ZZZ
If prompted with "Are you sure you want to continue connecting (yes/no)?", type yes and press Enter.
You should now be logged into your EC2 instance's command line.
Common Pitfalls and Troubleshooting
- Permission Denied (publickey):
- Ensure your
.pemfile haschmod 400permissions. - Verify you're using the correct key pair for the instance.
- Check if you're using the correct username (
ec2-userfor Amazon Linux,ubuntufor Ubuntu,adminorec2-userfor others).
- Ensure your
- Connection timed out:
- The most common reason is an incorrect security group configuration. Verify that your security group allows inbound SSH (port 22) from your current public IP address.
- Ensure the instance is actually running and passed its status checks.
- Check if there's any network ACL (NACL) blocking traffic (less common for beginners, as default NACLs allow all traffic).
- Lost your
.pemfile: You cannot regenerate or re-download the private key. You will need to create a new key pair, attach it to your instance (requires instance stop/start and potentially console-based intervention for key replacement), or launch a new instance with a new key pair. - Instance state stuck in "pending": This can occasionally happen due to AWS service issues or insufficient capacity in the chosen Availability Zone. Try stopping and starting the instance, or launching in a different AZ.
- Free Tier exceeded: While
t2.microand 8GB GP2 are free-tier eligible, be mindful of usage limits (e.g., 750 hours per month for t2.micro, 30GB EBS). Running multiple free-tier instances or exceeding storage can incur costs. Monitor your billing dashboard regularly.