Launch Your First AWS EC2 Instance


Introduction
Amazon EC2 (Elastic Compute Cloud) is a cloud service that provides resizable virtual servers (instances) for running applications. Developers and Operations teams use it to deploy and scale workloads with flexible cost and power.
EC2 Kick Starter Points ๐
Instances: Virtual machines with customizable CPU, memory, storage, and OS options (Linux, Windows, macOS, Raspberry Pi OS).
Scalability: Spin up or spin down instances on demand, or use auto-scaling based on traffic, CPU, memory, or custom metrics.
Pricing: Flexible pricing options โ Pay-as-you-go (On-Demand), Spot Instances, Reserved Instances, and Savings Plans.
Use Cases: Hosting web apps, running databases, batch data processing, machine learning training, and more.
Integrations: Manage instances using the AWS CLI, SDKs (Python, Java, Go, etc.), Terraform, and AWS CloudFormation.
Networking: Instances launch within a Virtual Private Cloud (VPC) for isolated networking and better security.
Storage: Attach persistent EBS volumes for long-term storage, or use ephemeral storage tied to the instance lifecycle.
๐ฏ Bonus Tips for Beginners
SSH Key Permissions:
If you're connecting from Linux or macOS, you must run chmod 400 your-key.pem
before using SSH. This secures your private key and prevents SSH connection errors.
Elastic IPs (EIP):
If you stop and start your instance, your public IP address may change. To keep a static public IP, allocate and associate an Elastic IP.
Instance Termination Reminder:
Always terminate unused instances when you're done to avoid unexpected AWS charges.
๐ ๏ธ Before You Begin
Make sure you have:
An AWS account (Free Tier eligible works great!)
Access to a terminal or command line (Linux, macOS, or Windows)
How to Launch EC2 Instance from the AWS Console
Log into AWS Management Console
Navigate to EC2 Service
In the "Find Services" bar, search for EC2 and click it.
Tip:
Check the AWS Region at the top right of the Console. Choose a region close to you for better performance and lower latency.
Click "Launch Instance"
- Under the EC2 Dashboard, click the Launch Instance button.
Name your instance
- Provide a simple name like:
my-first-instance
(this is optional but recommended).
- Provide a simple name like:
Select an Amazon Machine Image (AMI)
- Choose Amazon Linux 2 AMI (Free Tier eligible).
Choose an Instance Type
- Choose t2.micro (Free Tier eligible). If t2.micro is unavailable in your region, select t3.micro instead.
Create or Select a Key Pair
If you don't have one:
Click Create new key pair.
Key pair type: RSA.
Private key format: .pem (for Linux/macOS) or
.ppk
(for Windows).Download the
.pem
file and store it securely.
If you already have one, just select it.
Important:
Always create or use a Key Pair. If you proceed without a Key Pair, you won't be able to connect to your instance using SSH.
Configure Network Settings
Create a new Security Group.
Allow SSH (port 22) from your IP address.
(Optional) Allow HTTP (port 80) if you plan to serve a web app.
Configure Storage
Default 8 GB General Purpose SSD (gp2) is fine for testing.
You can increase if needed (but keep it Free Tier if testing).
Review and Launch
Review all settings.
Click Launch Instance.
View Instance
- After a few seconds, click View Instances to see your new EC2 running!
Connect to Your Instance:
Select your running instance.
Click Connect.
Follow the on-screen SSH connection instructions to securely access your EC2 server.
๐ How to Launch an EC2 Instance Using AWS CLI
Launching an EC2 instance from the AWS Command Line Interface (CLI) gives you faster automation and scripting abilities โ perfect for DevOps workflows.
๐ Before You Begin
Make sure you have the following ready:
AWS CLI installed
Check by running:aws --version
AWS credentials configured
Set them up using:aws configure
(You will need your Access Key ID, Secret Access Key, and a default AWS region.)
A Key Pair created
You need a Key Pair (
.pem
file) already created in the region where you are launching the instance.If you don't have one, you can create it via AWS Console or CLI.
A Security Group created
- Security Group must allow inbound SSH traffic (port 22) at minimum.
An AMI ID
For example, the Amazon Linux 2 AMI ID for
us-east-1
is commonlyami-0c2b8ca1dad447f8a
.You can find the latest AMI ID by running:
aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn2-ami-hvm-*-x86_64-gp2" --query 'Images[*].[ImageId,Name]' --output text
๐ ๏ธ Launch EC2 Instance Command
aws ec2 run-instances \
--image-id ami-0c2b8ca1dad447f8a \
--count 1 \
--instance-type t2.micro \
--key-name YourKeyPairName \
--security-groups YourSecurityGroupName
Parameter | Description |
--image-id | The AMI ID of the image you want to use (ex: Amazon Linux 2) |
--count | Number of instances to launch (usually 1 for testing) |
--instance-type | Instance size/type (t2.micro for Free Tier) |
--key-name | The name of your Key Pair for SSH access |
--security-groups | Name of the Security Group allowing access |
โก How to Check if the Instance was Created
After running the run-instances
command, you can verify the instance is running:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,PublicIpAddress]' --output table
This will show:
Instance ID
Instance State (pending/running)
Public IP Address
Once your instance shows a "running" state and a public IP address, it's ready for connection. ๐
You can now securely SSH into your instance using your Key Pair and start working with your first cloud server.
Reminder:
After testing, remember to terminate your instance to avoid unnecessary AWS charges!
Subscribe to my newsletter
Read articles from Manny directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Manny
Manny
Helping developers and engineers grow through cloud tutorials, backend projects, and honest tech reviews.