š Step-by-Step Guide: Launching an AWS EC2 Instance Using Amazon Linux (Free Tier)
Starting with AWS and want to learn how to create your first EC2 instance? In this post, I'll walk you through setting up an Amazon EC2 instance using a free tier account with an Amazon Linux machine, a key pair, and a new security group. Follow these steps to get started with your cloud journey!
What is Amazon EC2?
Amazon EC2 (Elastic Compute Cloud) provides scalable compute capacity in the cloud, allowing you to run virtual machines, or "instances." It's a fundamental building block of any AWS environment.
Why Use the Free Tier?
AWS offers a free tier for new users, giving you the ability to experiment and learn without incurring charges. This guide focuses on setting up an Amazon Linux instance, which is included in the free tier.
š Steps to Create an EC2 Instance in AWS
1. Sign in to the AWS Management Console:
2. Navigate to the EC2 Dashboard:
- In the search bar, type EC2 and click on it to open the EC2 dashboard.
3. Connect to Your EC2 Instance via SSH:
Open a terminal on your local machine.
Navigate to the directory where you saved the
.pem
file and run:bashCopy codechmod 400 MyEC2Key.pem
Use the following SSH command to connect (replace
<pub
lic-ip>
with your instanceās public IP):bashCopy codessh -i "MyEC2Key.pem" ec2-user@<public-ip>
4. Start Exploring:
- You now have shell access to your EC2 instance! You can install software, configure settings, or deploy applications directly on this instance.
š” Best Practices:
Restrict SSH Access: Limit SSH (port 22) access to specific IP addresses for better security.
Use Strong Key Pair Management: Keep your
.pem
file secure and do not share it.Leverage the Free Tier: Monitor your usage to stay within the free tier limits and avoid unexpected charges.
How to Launch an EC2 Instance and Connect via SSH in VS Code
Amazon EC2 (Elastic Compute Cloud) allows you to run virtual servers on the AWS cloud. In this guide, we will walk through creating an EC2 instance and connecting to it via SSH using Visual Studio Code (VS Code).
Step 1: Launch an EC2 Instance
Log in to AWS Management Console:
- Open the AWS Console and search for "EC2".
Click on āLaunch Instanceā:
Under the EC2 dashboard, select Launch Instance.
Configure Basic Details:
Name and Tags: Set the name as
MYEc2
.Application and OS Images (AMI): Choose Amazon Linux 2023 AMI (Free tier eligible).
Instance Type: Select
t2.micro
(Free tier eligible).Key Pair (Login): Choose or create a key pair (e.g.,
NewRSA21Aug
). Download the.pem
fileāitās required for SSH access.Network Settings: Use the default VPC and enable the Auto-assign public IP option.
Security Groups: Create a new security group with the following rules:
Allow SSH (port 22) from 0.0.0.0/0 (For better security, restrict this to your IP).
Allow HTTP (port 80) and HTTPS (port 443) for web access.
Configure Storage:
- By default, an 8 GiB root volume (EBS) is attached. Free tier users can get up to 30 GB of storage.
Review and Launch:
- Review all configurations and click Launch Instance.
Access Your Instance Details:
- After launching, go to the Instances page to find your instance's details, such as the public IP.
Step 2: Connect to Your EC2 Instance via SSH
Set Permissions for the Key Pair File:
On your local machine, navigate to the directory where you saved the
.pem
file and run:bashCopy codechmod 400 NewRSA21Aug.pem
Connect Using SSH:
Use the following command in your terminal (replace
<public-ip>
with your instanceās public IP):bashCopy codessh -i "NewRSA21Aug.pem" ec2-user@<public-ip>
Once connected, youāll have shell access to your EC2 instance.
Step 3: Connect to EC2 Using VS Code
Install the Remote - SSH Extension:
- In VS Code, go to the Extensions view (
Ctrl+Shift+X
) and install the Remote - SSH extension.
- In VS Code, go to the Extensions view (
Configure SSH in VS Code:
Open the command palette (
Ctrl+Shift+P
) and select Remote-SSH: Add New SSH Host.Use the following configuration:
bashCopy codessh -i "path/to/NewRSA21Aug.pem" ec2-user@<public-ip>
Replace
path/to/
with the actual path where your.pem
file is stored.
Connect to the Host:
From the command palette, choose Remote-SSH: Connect to Host and select the configured EC2 host.
Start Coding:
- Youāre now connected to your EC2 instance directly through VS Code. You can open files, edit code, and deploy applications easily from this environment.
Conclusion
By following these steps, you can set up and manage an EC2 instance, connect to it securely using SSH, and enhance your development experience by integrating it directly with VS Code.
For more AWS tips and guides, connect with me on LinkedIn!