Learn & Implement Contest - AWS UG OSTech Conf 2021
Tags: aws, docker, opensource, awsugjaipur
Published: 2021-07-14 16:38:10

This contest is a part of [AWS UG OSTech Conf 2021](https://awsugjaipur.tech)

**Prerequisite: Must have access to AWS console
Disclaimer: We have used AWS EC2 t2.micro instance that is free tier eligible still can cause billing, It's user responsibility to terminate instance after performing the contest.**

## Step1: Launching EC2 instance

1.1) In AWS Console, search for EC2 and click on that service, you will be redirected to the AWS EC2 page as follows and then click on Launch Instance.
![Launching EC2 Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxpn57brfpofhyi9jdjv.jpeg)


1.2) To run EC2 successfully, select an **Amazon Machine Image (AMI)**. AMI contains all the software configurations (Operating System, Application Server, and applications) required to launch your instance. In this case, we will pick Amazon Linux AMI.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsw1ws9gj30lsi3usn65.png)

1.3) Now, select the **Instance Type** that determines the type of CPU, storage, network capacity, and memory needed during the installation. Choose **t2.micro**, and hit the next button as shown below:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/umit0nao3iz7z6kysaad.png)

1.4) Click the **Next** button until you reach the Configure Security Group page to retain the default settings. A security group is a set of firewall rules that control the traffic for your instance. On this page, you can add rules to allow specific traffic to reach your instance.

For example, if you want to set up a web server and allow internet traffic to reach your instance, add rules that allow unrestricted access to the HTTP and HTTPS ports.
It's must to put 22 port on my_ip field.
Enter the Security Group name and then hit the **Review and Launch button**.  
 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76g98ajcubwcurqvpfiv.png)
 
 
1.5) After hitting the Launch button you will see a pop-up page that requires you to select a **Key Pair**. This contains both a public and private key folder that is used to connect to your EC2 Instance securely via SSH. Click on the **create a new key pair** button and give a name to the key pair. Go ahead and download your key pair.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olyly4z5pim4fp5nkd2p.png)

1.6) Save your key file to a safe place on your system and then click on Launch Instances, it will direct you to the launching page. Hit the **View Instances** button to access the EC2 Instances page, then click on connect and you will see several options to connect your instance, it will only need SSH to be installed and the **pem key** that you have downloaded, mentioned in the previous step.

Copy **ssh** command provided there and use it to connect, you can use Git Bash, CMD, or Putty.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6amyd285dolxbju99v26.png)

## Step 2: Install required tools and packages

2.1) After connecting to the instance via SSH, now run the below commands -
```
 sudo su 
 yum update -y
 yum install docker git -y
 systemctl start docker
 usermod -a -G docker ec2-user
 systemctl enable docker
```
These commands will install Docker and Git in your AMI, and enable your Docker service.  

2.2) Now you have to clone a repository and modify a file by replacing AWS with your **Full Name** by using the below commands - 
```
 git clone https://github.com/AWS-User-Group-Jaipur-Rajasthan/OSTechConf21.git
 cd OSTechConf21/contests/learn-and-implement/
 sed -i 's/I am/AWS/g' learn/index.html
```
> Note: Don't forget to replace AWS with your name like :-
`$ sed -i 's/I am/Elon Musk/g' learn/index.html`

## Step 3: Build Image and Run Container

First, check that you are in the **learn-and-implement/** folder and a **Dockerfile** is present.
_This command will build the image_
```
docker build -t 'ostechconf21' .
``` 
_This command will run your docker container in which web page is hosted_
```
docker run -p 80:80 -d ostechconf21
```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjfz2509lq9q6o1nt82t.png)
 
It's Done! 🥳

## Step 4: Final Steps

4.1) Open the **Amazon EC2 console** and in the navigation pane, choose Instances and select your instance.

The following information is available on the Networking tab:
Public IPv4 DNS — The external DNS hostname.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k2ybq3ibdqw76u4abvdi.png)

4.2) Copy the Public DNS and paste that in any browser. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zh48vn09njrgpxtf955r.png)

> Congratulations !! If you can see your webpage with your name as above screenshot.

4.3) Now go to EC2 console and copy instance Public DNS and open that in any browser and share the screenshot as given on contest page.

**Connect with AWS UG Jaipur:**
[YouTube](https://www.youtube.com/c/AWSUserGroupJaipurRajasthan/) | [LinkedIn](https://www.linkedin.com/company/awsjaipur) | [GitHub](https://github.com/AWS-User-Group-Jaipur-Rajasthan)