- Log in to your AWS Management Console.
- Navigate to the EC2 Dashboard.
- Click Launch Instance and configure the following:
- AMI: Choose an Amazon Machine Image (e.g., Amazon Linux 2 AMI).
- Instance Type: Select an instance type (e.g.,
t2.microfor free-tier eligibility). - Key Pair: Choose an existing key pair or create a new one for SSH access.
- Security Group: Configure rules to allow required traffic (e.g., HTTP, HTTPS).
- Storage: Specify the root volume size (default: 8GB).
- Review and click Launch to create the instance.
- Open your terminal and ensure AWS CLI is installed and configured.
- Run the following command to create an EC2 instance:
Replace /path/to/your-key.pem with the path to your private key file and <PUBLIC_IP_ADDRESS> with your instance's IP.
aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ # Replace with your desired AMI ID --count 1 \ --instance-type t2.micro \ --key-name MyKeyPair \ # Replace with your key pair name --security-group-ids sg-0123456789abcdef0 \ # Replace with your security group ID --subnet-id subnet-0abcd1234efgh5678 # Replace with your subnet ID
Update the system:
sudo yum update -yInstall necessary packages:
sudo yum install -y httpdTo stop or terminate the instance, use the AWS Management Console or the following CLI commands:
- Stop the instance:
aws ec2 stop-instances --instance-ids <INSTANCE_ID>- Terminate the instance:
aws ec2 terminate-instances --instance-ids <INSTANCE_ID>Always ensure your IAM user or role has the necessary permissions. Choose the appropriate region for your instance.
This project is licensed under the MIT License. See the LICENSE file for details.
This version focuses purely on creating the instance. You can handle the SSH connection in a separate README or file. Let me know if you'd like that!