Prerequisite: - A valid AWS account IAM Permission: Min EC2 Full Access,EC2InstanceConnect Challenge :- Deploy a Website on an EC2 instance...
Prerequisite:- A valid AWS account
IAM Permission: Min EC2 Full Access,EC2InstanceConnect
Challenge:- Deploy a Website on an EC2 instance and should be accessible on Port 80. Below is the configuration for the website.
OS:- ubuntu 18.04
Webserver: Apache
Firewall to open(Inbound): 22,80
Web Pages: HTML
Region: Select Region where you want to deploy the application.
Solution: Create an EC2 instance and install apache on top of it and attach a security group that has an inbound rule to open port number 22,80. Use public IP address to access the application on a browser.
Steps to Follow
Step 1:- Create a key-value pair ( If you already have a valid public key (.pem or .ppk for putty then no need to perform this step)
- Click on Network & Security---> keypairs
- Click on Create a key pair button
- Fill out the form by entering Name vdevops
- Key pair type:- RSA
- Private key format:- .pem
- Click on Create key pair.
- Key should be listed in keypair list and a vdeops.pem file should be downloaded on your system ( keep it in some location in your computer so that we can refer it whenever it is required).
Step 2: Create Security Group (To open the firewall with defined port numbers). If you already created the security group then this step is optional.
- Select Network & Security--->Security Group
- Click on Create Security Group Button
- Fill out the form by entering below details
- Security Group Name: sgWebServer
- Description: Allow Http and SSH
- No change in vpc value
- Inbound rules:- Click on Add rule Button
source : AnyWhere-IPV4
- Click on Add rule Button
source : AnyWhere-IPV4
Step 3: Create an EC2 instance
- Search Service EC2 in the search box and select EC2 from the search list.
- Select Instances and Click on Launch Instances
- Select AMI (Amazon Machine Image) - ubuntu 18.04
- Select Instance Type t2.micro and Click on Next Button
- Instance Details - Leave as it is because we are not making any change in VPC or subnet etc. On the Same page at the bottom select User Data and select As text and enter the below code.
#!/bin/bashsudo susudo apt updatesudo apt install apache2 -y
- Click on Next
- Add Storage :- No Change
- Click on Next
- Add Tags:- Click on Add Tags button
value: WebServer
- Click on Next
- Configure Security Group
- select the option :- select an existing security group
- From the below list select sgWebServer
- Click on Review and Launch
- Review and Launch Page :- Click on Launch
- select existing keypair :- vdevops
- click on acknowledge checkbox and click on Launch Instances
- On Launch Status Page Click on the view instances button
- In the Instances list, you will find an EC2 instance which is WebServer
- Wait for this instance to be in running status.
Step 4: Connect to EC2 Instance - WebServer
- For Windows
- Open MobaXterm Click on session---> SSH
- Remote Host: public ip address of Ec2 instance
- user name: ubuntu
- Click on Advance SSH Settings
- click on use Private key checkbox
- select path for your vdevops key and click Ok Button
- Terminal should be connected with EC2 instance
Step 5: Deploy Web page on this EC2 instance
- Login with root user :- sudo su
- Check apache is already installed because we have mentioned apache installation script in USER DATA
- systemctl status apache2
- Create an index.html.
- echo "<h1>This is my first web page on AWS EC2 instance </h1>" > /var/www/html/index.html
Step 6: Visit the website on Browser
On Browser enter URL as PublicIP address of Webserver EC2 instance and you will be able to see the web page with above contents.
Few Experiments
- Stop EC2 instance and check that web page is opened or not
- Start EC2 instance and now again check the web page is getting opened or not
- Remove port number 80 from sgWebServer SG and check webpage is getting opened or not
- Add port number 80 from sgWebServer SG and check webpage is getting opened or not
COMMENTS