Firstly, follow these steps to Create an EC2 Instance
- Go to Compute section and select EC2
- On the EC2 dashboard, you will see “Running instances” under the “Resources” section with count as 0 (because you have not created any instance yet).
- Create an instance by clicking on the “Launch Instance” button.
Step 1: Choose any AMI (Amazon Machine Image)
- This page will list out the Amazon pre-defined AMI’s like Linux, Red Hat, Ubuntu, Microsoft, etc.
- My AMI’s: It will be listing of AMI’s created by you.
- AWS Marketplace: It will be listing of AMI’s provided by 3rd party vendors. So each machine has different pricing.
- Community API: It’s a category-wise listing of AMI’s provided by different communities, with other selection of things. These are open-source operating systems and here AMI’s will be free.
- You can choose the AMI as per your requirement.
Lets choose Amazon Linux AMI and click on “Select”
Step 2: Choose an Instance Type
- This page will list out all the types of instances, vCPU’s, with their respective memory and storage, etc.
- You can choose it as per your requirements.
Lets choose “t2.micro” (Free tier) and click on “Next”
Step 3: Configure Instance Details
- On this page, where you can configure your instance as per your requirements like choosing the number of instances, Purchase options, etc. Now you can launch 100 instances per account.
- If you enable ‘Request Spot Instances’, you need to bid for the instance by providing the maximum price. Spot instances are only used for testing purposes.
- If someone bids higher than you, this Spot instance will be taken back from you. These instances are just given to you for a small amount of time.
Lets use the default settings and just click on “Next”
Step 4: Add Storage
- This page will show the default volume, associated with the selected instance type.
- You can increase the size of the volume or can add other EBS volumes as per your requirements.
Lets use the default storage and just click on “Next”
Step 5: Add Tags
- Tags are used to recognize instances/machines.
- It will be a key-pair value and you can add another tag (up to 50)
- Click on the “Add Tag” button to add the details.
I will add key = ‘name’ and value = ‘FirstEC2Instance’ and just click on “Next”
Step 6: Configure Security Group
- On this page, you can set specific rules to allow traffic to access your instance.
- You can either create a new Security group and can choose from the existing one.
I will add the rules for HTTP & HTTPS tyle, by clicking on the “Add Rule” button. Click on “Review and Launch” button to move to the final step
Step 7: Review
- This page will show the instance details like AMI, Instance Type, Security Groups, Instance details, Storage and Tags (which you have selected from previous steps)
After reviewing all these details, click on the “Launch” button to launch your instance.
- Once clicked on the “Launch” button, it will ask for key-pair.
- You can either create a new key pair or choose from the existing one.
- For Linux, this private key file will allow you to securely access your instance.
I will create a new key pair with the name “FirstEC2Instance” and click on the “Download Key Pair” button because this is the only time to do that. Now click on the “Launch Instances” button.
Launch an EC2 Instance
- Go back to EC2 Dashboard and click on “Instances” and you will see the newly created instance in “running” mode.
- Select this new instance and click the “Connect” button.
- Clicking on the “Connect” button will give you instructions about connecting to the instance.
- To connect your instance using SSH, you must know your IP address.
- Click on the newly created instance and under the Description tab you will see “Public IP”, which you can use for connecting to this instance.
Connect to Instance
Login to this newly created instance by Putty (on Windows) or terminal (on Linux), using SSH command
# ssh -i <PATH-OF-PEM-FILE> ec2-user@<IP-ADDRESS>
Connect as a root user
# sudo su
To update the latest packages and updates
# yum update -y
Make it a webserver/ Install Apache
# yum install httpd
Check if it’s running
# service httpd status
To start the server
# service httpd start
Go to Apache directory
# cd /var/www/html
Create a dummy file there and add some text there “Demo page”, using vi editor
# vi demo.html
Open the browser, by typing the Public IP of a newly created instance with the name of demo file like:
You will see the webserver/ newly created instance with running Apache is working fine.