Amazon EC2 (Elastic Compute Cloud) allows you to create virtual servers in the AWS cloud. These servers can be used to host websites, applications, databases, development environments, and other workloads.
Prerequisites
Before launching an EC2 instance, you should have:
- An active AWS account
- Access to the AWS Management Console
- A suitable AWS Region selected
- Basic knowledge of Linux or Windows, depending on the operating system you choose
Step 1: Sign in to AWS
Open the AWS Management Console and sign in to your AWS account.
From the AWS Console, search for EC2 and select the EC2 service.
Step 2: Launch an Instance
On the EC2 dashboard, select Launch instance.
You will be taken to a configuration page where you can define the settings for your virtual server.
Step 3: Choose an Instance Name
Enter a descriptive name for your instance, such as:
My-Web-Server
Using meaningful names makes it easier to identify your resources later.
Step 4: Choose an Amazon Machine Image (AMI)
An AMI determines the operating system and initial software installed on your EC2 instance.
Common choices include:
- Amazon Linux
- Ubuntu
- Microsoft Windows Server
- Red Hat Enterprise Linux
For a typical Linux web server, Ubuntu or Amazon Linux is a good starting point.
Step 5: Select an Instance Type
Choose the hardware configuration for your server.
The instance type determines resources such as:
- CPU
- Memory
- Network performance
- Pricing
For learning and testing, a small instance type that is eligible for your AWS Free Tier, if applicable to your account, is generally sufficient.
Step 6: Create or Select a Key Pair
A key pair is used to securely connect to your EC2 instance.
Select an existing key pair or create a new one. If creating a new key pair, download the private key file and store it securely.
Important: AWS generally cannot provide the private key again if you lose it, so keep a secure backup.
Step 7: Configure Network Settings
Configure the networking options for the instance.
You can select:
- VPC
- Subnet
- Auto-assign public IP
You also need to configure a Security Group, which acts as a virtual firewall.
For example, a web server may need:
- SSH (port 22) for Linux administration
- HTTP (port 80) for websites
- HTTPS (port 443) for secure websites
For SSH, restrict access to trusted IP addresses whenever possible instead of allowing access from everywhere.
Step 8: Configure Storage
AWS provides default storage settings, but you can adjust them according to your requirements.
For example, you might configure:
- Root EBS volume
- Storage capacity
- Volume type
- Encryption
For basic testing, the default storage configuration is often sufficient.
Step 9: Review the Configuration
Before launching, review your settings carefully.
Check the:
- AMI
- Instance type
- Key pair
- Network and subnet
- Security group
- Storage configuration
Also review the estimated cost and applicable Free Tier eligibility.
Step 10: Launch the Instance
Click Launch instance.
AWS will create the virtual machine using the configuration you selected.
After a short time, you can return to the EC2 Instances page and see your new instance.
Its state should eventually change from Pending to Running.
Step 11: Connect to the EC2 Instance
Once the instance is running, select it and choose Connect.
AWS provides several connection methods depending on the operating system and configuration.
For a Linux instance, you can typically connect using SSH. For example:
ssh -i your-key.pem username@your-public-ipThe username depends on the AMI you selected.
For example, Amazon Linux commonly uses
ec2-user , while Ubuntu commonly uses ubuntu .Step 12: Test the Instance
After connecting, you can run basic commands to verify that the server is working.
For example:
uname -aYou can also update packages and install software required by your application.
If you are creating a web server, you could install a web server such as Apache or Nginx and then access it through the instance's public IP address.
Step 13: Stop or Terminate the Instance
When you are finished, remember to manage the instance to avoid unnecessary charges.
- Stop the instance when you want to shut it down temporarily and potentially start it again later.
- Terminate the instance when you no longer need it. Termination permanently removes the instance, although associated resources may require separate cleanup.
Conclusion
Launching an EC2 instance involves choosing an AMI, selecting an instance type, configuring authentication and networking, setting up storage, and then starting the instance. Once it is running, you can connect to it and install the software required for your application.
For production workloads, you should additionally consider security groups, IAM permissions, backups, monitoring, encryption, patching, networking, and cost management.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article