Launching and Managing EC2 Instances
Example launching an EC2 Instance
- Instance Name: MyFirstInstance
- AMI Selection: Amazon Linux
- Instance Type: t2.micro
- Key Pair:
- Creation of a new key pair named
DemoKeyPair
- Key type: RSA pem
- Network Settings:
- Creation of a new security group named
AWSSSH
- SSH allowed on port 22 from anywhere
- Storage: Default settings
- Instance Launch: Successfully launched the instance
Connecting to the EC2 Instance
- Method 1: SSH
- Change permissions of the key pair file:
chmod 400 DemoKeyPair.pem
- Connect via SSH:
ssh -i DemoKeyPair.pem ec2-user@<Public-IP>
- Test command:
echo "hello world"
- Method 2: EC2 Instance Connect
- Use the EC2 console to connect with EC2 Instance Connect
- Username:
ec2-user
- Test command execution within the instance
Changing the EC2 Instance Type
- Prerequisite: Instance must be EBS-backed
- Steps:
- Stop the instance
- Change the instance type (e.g., from t2.micro to t2.small for more RAM and CPU)
- Start the instance again
- Example:
- Create a file
hello.txt with content "hello"
- Check available memory with
free -m (Original: 993 MB RAM)
- Stop the instance
- Change instance type to t2.small
- Start the instance
- Reconnect and verify:
- File
hello.txt persists
- Available memory increased to 1991 MB RAM
- Note: Changing to a non-free tier instance type will incur charges. Remember to revert back to t2.micro to stay within the free tier.
Key Takeaways
- Ensure your instance is EBS-backed to retain data after stopping and starting.
- Changing the instance type allows you to scale the instance's resources according to your needs.