Introduction
In this project, you will launch an Amazon EC2 (Elastic Compute Cloud) instance and securely connect to it using SSH. EC2 allows you to run virtual machines (called instances) in the AWS Cloud. This is useful in the real world for:
Prerequisites
Step-by-Step Implementation
Below are the manual steps (through the AWS Console) and the CLI commands side by side for each phase. You can choose whichever method you prefer or do both to reinforce learning.
Step A: Configure AWS CLI (if using CLI)
Explanation:
This command sets up your AWS credentials and default region.
You will be prompted for:
AWS Access Key ID
AWS Secret Access Key
Default region name (e.g., us-east-1)
Default output format (e.g., json)
Step B: Create a Key Pair AWS Console (GUI)
Go to EC2 service in your AWS Console.
In the left navigation pane, under Network & Security, click on Key Pairs.
Click Create key pair.
Give it a name (e.g., my-ec2-keypair), choose RSA key type, .pem format.
Save the downloaded .pem file in a secure location on your local machine.
CLI :
aws ec2 create-key-pair \
--key-name my-ec2-keypair \
--query "KeyMaterial" \
--output text > my-ec2-keypair.pem
Explanation:
Set Permissions (CLI only)
Explanation:
This ensures the private key file is not publicly viewable.
Required by SSH for security.
Step C: Launch an EC2 Instance
AWS Console (GUI)
Go to the EC2 dashboard.
Click Launch instances.
Name and tags: Enter a name for your instance (e.g., MyFreeTierInstance).
Application and OS Images (Amazon Machine Image): Select Amazon Linux 2023 or similar free tier eligible AMI.
Instance type: Choose t2.micro (Free Tier eligible).
Key pair (login): Select the key pair you just created (my-ec2-keypair).
Network settings:
Make sure you create (or select) a security group that allows SSH (port 22) inbound from your IP or from anywhere if you are just testing.
Leave storage to the default 8GB (within Free Tier limits).
Click Launch instance.
CLI :
aws ec2 run-instances \
--image-id ami-0c02fb55956c7d316 \
--instance-type t2.micro \
--key-name my-ec2-keypair \
--security-group-ids sg-1234567890abcdef0 \
--subnet-id subnet-12345678 \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=MyFreeTierInstance}]' \
--count 1
Explanation:
Step D: Check Instance Status AWS Console (GUI)
Return to your EC2 Instances page.
You should see your new instance in the list, with a status of Running once it is ready.
Wait for the Status Checks to turn 2/2 checks passed.
CLI :
aws ec2 describe-instances --filters "Name=tag:Name,Values=MyFreeTierInstance"
Explanation: describe-instances displays information about your instances. --filters helps narrow the results by matching the “Name” tag you assigned.
Step E: Connect to EC2 via SSH
Obtain Public IP (AWS Console or CLI) Console: On the Instances page, under Description, note the Public IPv4 address.
CLI: From the previous describe-instances output, find the field "PublicIpAddress": "YOUR_IP_HERE".
Connect using SSH : ssh -i /path/to/my-ec2-keypair.pem ec2-user@PUBLIC_IP_ADDRESS
Explanation: ssh -i specifies your private key. ec2-user is the default username for Amazon Linux. (Other AMIs may have different usernames like ubuntu or centos.) Replace PUBLIC_IP_ADDRESS with the actual IP you noted.
Conclusion
By doing this project , we have successfully:
Skills Learned:
With these skills, you can further explore deploying software on your EC2 instance, scaling your environment, or automating more complex tasks.
Popular Projects
What is Cloud Computing ?
Cloud computing delivers computing resources (servers, storage, databases, networking, and software) over the internet, allowing businesses to scale and pay only for what they use, eliminating the need for physical infrastructure.