Update Config File
Before we create and configure the web instances, open up the application-code/nginx.conf
file from the repo we downloaded. Scroll down to line 58 and replace [INTERNAL-LOADBALANCER-DNS]
with your internal load balancer’s DNS entry. You can find this by navigating to your internal load balancer's details page.
DNS Name is,
Copy the above DNS name and replace it in your nginx.conf
file.
Then, upload this file and the application-code/web-tier
folder to the S3 bucket you created for this lab.
Web Instance Deployment
- Navigate to the EC2 service dashboard and click on Instances on the left-hand side.
- Click Launch Instances.
- Select the first Amazon Linux 2 AMI.
- Choose the free-tier eligible T2.micro instance type and click Next: Configure Instance Details.
- Proceed without a key-pair as we will use EC2-instance login.
- Configure instance details:
- Select the correct Network, Subnet, and IAM Role created earlier.
- Use one of the private subnets created for the app layer.
- Use the already created VPC and Public Subnet AZ-1, and enable auto-assign Public IP.
- Assign the Web Tier Security Group.
- Use the IAM Role created for the web tier.
- Click Launch Instance.
Connect to Instance
- Navigate to your list of running EC2 Instances by clicking on Instances in the EC2 dashboard.
- When the instance state is running, select the instance and click the Connect button.
- Select the Session Manager tab and click Connect to open a new browser tab.
- Test connectivity by running the following command:
sudo -su ec2-user
ping 8.8.8.8
Configure Web Instance
Install NVM and Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install 16
nvm use 16
Download Web-Tier Code from S3
cd ~/
aws s3 cp s3://BUCKET_NAME/web-tier/ web-tier --recursive
Build the React App
cd ~/web-tier
npm install
npm run build
Install and Configure Nginx
sudo amazon-linux-extras install nginx1 -y
Configure Nginx
- Navigate to the Nginx configuration file:
cd /etc/nginx
ls
- Delete the existing
nginx.conf
file and replace it with the one from S3:
sudo rm nginx.conf
sudo aws s3 cp s3://BUCKET_NAME/nginx.conf .
- Restart Nginx:
sudo service nginx restart
- Ensure Nginx has permission to access files:
chmod -R 755 /home/ec2-user
- Enable Nginx to start on boot:
sudo chkconfig nginx on