AWS Hybrid Cloud Testing – Part 5 – Host static website on Elastic File System (EFS)

As you may already know, there are few ways to host a static website in AWS.

  • Host the static website on s3 bucket and then use route 53 to re-point the s3 bucket website end point to your custom website. This is probably the cheapest option. OR
  • Use CloudFront distribution to distribute s3 bucket website end point and then use route 53 to re-point the CloudFront domain name to your custom website. This will incur costs. OR
  • Host the static website on EFS and mount the EFS on your EC2 instance. This will also incur costs.

Point two has already been explained in an earlier post: AWS Hybrid Cloud Testing – Part 2 – Distribute static website over Cloudfront

In this post, I will explain how static website can be hosted on EFS and how to test them.

When you create EC2 instance and host a website on it, it is usually hosted on the /var/www/html directory, within the EC2 instance.

When using EFS, the file(s) is stored in a related EFS directory which is mounted on the EC2 instance. This way, the same EFS can be mounted across multiple EC2 instances where these multiple instances serve the same content to customers.

In my example, I have two EC2 instances (one in ap-southeast-2B and the other in ap-southeast-2c, Sydney region), that are accessed over an application Load Balancer ( Having two EC2 instances across two different availability zone means that the static website will have high availability and in the event that one of the EC2 instance crashes, the static website will still be served.

An Elastic File System (EFS) instance is then created and mounted on WebServer1. To mount the EFS on WebServer1, SSH to the EC2 instance and then execute the below command. Basically, I am mounting EFS on the EC2 directory of /var/www/html.

sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport /var/www/html

Here, is the EFS DNS name. In the new EFS layout in AWS console, the DNS name is not defined and hence needs to be derived from the file system ID. So if the file system ID for EFS is “fs-f50ad7cd” then the DNS name will be “ (

At the beginning, the two EC2 instances host different websites.

WebServer1 (with public IP address of is now mounted with EFS and hence shows below site which is hosted on EFS.

On the other hand, WebServer2 (public IP address of is still showing the old website, since it is not mounted on EFS yet.

Repeat the same EFS mounting exercise for WebServer2 and both the EC2 instances are now displaying the same content, hosted on EFS.

So what does static website hosted on EFS mean where the EFS is mounted on multiple EC2 instances?

It means:

  • I have high availability for my static website. If one of the EC2 instances crash, the website content will still be served by the other EC2 instance(s).
  • I only need to make website change in one location (/var/www/html is common to all EC2 instances) and all the EC2 instances will distribute the same content.
  • It will now take me a single command to mount EFS on additional EC2 instances.
  • With Application Load Balancer (ALB) and appropriate routing policy, the traffic is shared across multiple EC2 instances. This means that a single EC2 instance does not need to carry all the traffic, thereby addressing potential bottlenecks.

To test this system, you need to consider below test scenarios:

  1. Test the performance of EFS as more EC2 instances are mounted
  2. As the website content is updated in /var/www/html, verify that the content is available immediately across all EC2 instances.
  3. Test different routing policies for route53 that the static website content is correctly delivered to correct EC2 instances

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.