Wednesday, February 10, 2021

AWS - Create a VPC and an EC2 based Web Server


 


In this post we will review the steps to use AWS for creation of a VPC, and deployment of a sample web server on a new EC2 instance.

The steps are:

  • Login to AWS Management Console
  • VPC
  • Subnet
  • Internet Gateway
  • Routing Table
  • EC2 instance
  • Elastic IP
  • Security Group
  • Web Server


Login to AWS Management Console


To use AWS, you should get an account. In most cases, you already have an account paid by the company where you're employed at. In case you are working on you own, you can start with AWS Free Tier based account.

Once your account is setup, login to the AWS Management console.


VPC


A VPC is a Virtual Private Cloud, a logically isolated private network that you use for your servers. The VPC can include multiple network subnets. 
In the AWS management console, use the search box at the top to locate the VPC service, an open it.
Next click on Your VPCs in the left menu, and then on Create VPC.
Fill in the following:
  • Name: sample-vpc
  • IPv4 CIDR: 10.0.0.0/16
and click Create VPC.




Subnet


A subnet is a network segment that is part of a VPC. It has its own routing table, and security groups.

To add a subnet click on Subnets in the left menu, and click Create Subnet.
Fill in the following:
  • vpc: sample-vpc
  • name: sample-subnet
  • IPv4 CIDR: 10.0.0.0/24
and click Create Subnet.




Internet Gateway


An internet gateway is a logical router allowing access from and to a subnet.

To add an internet gateway click on Internet Gateways in the left menu, and click Create internet gateway.
Fill in the following:
  • name: sample-internet-gateway
and click Create internet gateway.

Now click on Actions, Attach to VPC, and select the sample-vpc.





Routing Table


Routing table configures how do we access from and to a subnet. 
We will configure access from and to the subnet to the internet through the internet gateway.
Open the VPC service in AWS console, click on Route Tables in the left menu, and select the route table related to the VPC.
Next add route destination 0.0.0.0/24 to the internet gateway that we have created.





EC2 Instance


An EC2 instance is a virtual machine running within the VPC on the cloud.


In the AWS management console, use the search box at the top to locate the EC2 service, an open it.
Follow the next steps:
  • Click on the Launch instance button
  • Select "Amazon Linux 2"
  • Select t2.macro, and click next
  • Select the sample-vpc, and the sample-subnet, and click review and launch
  • Click launch
  • Create a new key pair and save it locally
  • Click Launch instance
A few seconds later the EC2 instance is already running.





Elastic IP


Elastic IP is a static public IP that is allocated by AWS for our use.
To create an Elastic IP, open the VPC service in AWS console, click on Elastic IPs in the left menu, and click Allocate Elastic IP address, and click Allocate.
Next click on the added IP, and click on Associate Elastic IP address, add fill in the EC2 instance name, the the IP of the EC2 instance (all these fields have auto-fill, you do not need to keep notes...), and click associate.





Security Group


A security group configures the rules that allow access to an entity such as a EC2 instance and a Subnet.
We need to allow access to the EC2 instance on port 80.
Open the VPC service in AWS console, click on Security Groups in the left menu, and select the security group that was automatically added as part of the EC2 server creation (the name should look like launch-wizard-1).
Edit the inbound rules, and add HTTP access from all IPs 0.0.0.0/0.






Web Server


We will setup a sample web server based on the juice shop project.

SSH to the EC2 using the IP that was allocated by AWS for the Elastic IP, and the key pair that we have created as part of the EC2 instance creation.


ssh -i keypair.pem ec2-user@3.128.70.18
sudo yum -y install docker
sudo service docker start
sudo docker run -d --rm -p 80:3000 bkimminich/juice-shop


and our site is up, and accessible through the public web:





Final Note


In this post we have reviewed the basic steps to setup a public web server on AWS using VPC and an EC2 instance.
This is only a basic quick-start setup which does not handle the security implications, and the availability considerations, but it can provide a great boost for your first project.



No comments:

Post a Comment