Creating an EC2 instance in AWS involves several steps that you can follow through the AWS Management Console. Here’s a detailed guide to help you through the process:
Step-by-Step Guide to Creating an EC2 Instance
Step 1: Sign in to the AWS Management Console
- Open your web browser and go to the AWS Management Console.
- Sign in with your AWS account credentials.
Step 2: Navigate to EC2
- In the AWS Management Console, type “EC2” into the search bar and select “EC2” from the dropdown list.
- This will take you to the EC2 Dashboard.
Step 3: Launch Instance
- On the EC2 Dashboard, click the “Launch Instance” button.
- This begins the process of setting up your new EC2 instance.
Step 4: Choose an Amazon Machine Image (AMI)
- Select an AMI: An AMI is a template that contains the operating system, application server, and applications for your instance. AWS provides several free AMIs, including Amazon Linux, Ubuntu, Windows Server, and more.
- Choose the AMI that best fits your needs.
Step 5: Choose an Instance Type
- Select an Instance Type: EC2 offers a variety of instance types that differ in CPU, memory, storage, and networking capacity.
- For a simple web server, you might choose a t2.micro instance, which is free tier eligible and suitable for low-traffic applications.
- Click “Next: Configure Instance Details” after selecting the instance type.
Step 6: Configure Instance Details
- Number of Instances: Set the number of instances you want to launch.
- Network: Choose the VPC (Virtual Private Cloud) where the instance will reside. You can use the default VPC or create a new one.
- Subnet: Select a subnet that determines the Availability Zone in which your instance will launch.
- Auto-assign Public IP: Choose whether the instance should have a public IP address (useful if you need to connect to it directly from the internet).
- IAM Role: (Optional) If you want the instance to have permissions to access other AWS services, assign an IAM role here.
- User Data: (Optional) Add scripts that will run automatically when the instance starts. This can be used to install software, apply patches, etc.
Click “Next: Add Storage” when you’re done configuring the instance details.
Step 7: Add Storage
- Root Volume: Specify the storage size and type for the root volume (where the operating system will be installed). The default size is typically sufficient, but you can increase it if needed.
- Additional Volumes: (Optional) Add additional EBS volumes if your application requires more storage.
- Click “Next: Add Tags” after configuring the storage.
Step 8: Add Tags
- Tags: Tags are key-value pairs that help you organize and manage your instances. For example, you can add a tag with
Key = Name
andValue = WebServer
to identify this instance as a web server. - Click “Next: Configure Security Group” when you’re finished adding tags.
Step 9: Configure Security Group
- Security Group: A security group acts as a virtual firewall for your instance to control inbound and outbound traffic.
- Create a new security group: Set rules to allow traffic to your instance.
- Add a rule to allow SSH access (port 22) if you’re using Linux, or RDP (port 3389) for Windows.
- Add another rule to allow HTTP (port 80) or HTTPS (port 443) traffic if you’re setting up a web server.
- Use an existing security group: If you already have a security group set up with the necessary rules, you can select it here.
- Create a new security group: Set rules to allow traffic to your instance.
Click “Review and Launch” when done.
Step 10: Review and Launch
- Review your settings: Check the instance details, storage options, and security groups to ensure everything is set up correctly.
- Click “Launch” to proceed.
Step 11: Select a Key Pair
- Key Pair: A key pair is used to securely connect to your instance via SSH (for Linux) or RDP (for Windows).
- Create a new key pair: If you don’t have a key pair, create one and download the private key file (.pem). Store this file securely as you will need it to connect to your instance.
- Use an existing key pair: If you already have a key pair, select it.
- Acknowledge that you have access to the selected private key and then click “Launch Instances.”
Step 12: View Your Instance
- Click “View Instances” to go to the EC2 dashboard, where you can see the status of your newly launched instance.
- Instance State: The instance will initially be in a “pending” state and will transition to “running” once it’s ready.
Step 13: Connect to Your Instance
- Once the instance is running, you can connect to it:
- Linux Instance: Use an SSH client like PuTTY (for Windows) or Terminal (for macOS/Linux) to connect using the key pair you created.
- Example SSH command:
bash
ssh -i /path/to/your-key.pem ec2-user@your-instance-public-dns
- Example SSH command:
- Linux Instance: Use an SSH client like PuTTY (for Windows) or Terminal (for macOS/Linux) to connect using the key pair you created.
-
- Windows Instance: Use Remote Desktop Protocol (RDP) to connect.
- Download the RDP file from the AWS Management Console and connect using the instance’s public IP address.
- Windows Instance: Use Remote Desktop Protocol (RDP) to connect.
Conclusion
You’ve successfully created and launched an EC2 instance in AWS! From here, you can configure the instance as needed, install software, deploy applications, and manage it through the AWS Management Console or CLI. EC2 provides you with scalable, on-demand computing resources, making it easy to scale your applications as your needs grow.