Set up Web Application with EFS on AWS cloud using Terraform

Arvind Ramugade
4 min readSep 1, 2020

We’ll be setting up Web application on AWS with EFS as a storage instead of EBS volume.

  1. Create Security group which allows inbound connection on port 80 for http
  2. Create the key-pair
  3. Create VPC, Subnet, Internet gateway, Route table
  4. Launch EC2 instance using above security groups & key-pair
  5. Launch one Volume using the EFS service and attach it in your vpc, then mount that volume into /var/www/html
  6. Developer have uploaded the code into github repo also the repo has some images.
  7. Copy the github repo code into /var/www/html
  8. Create S3 bucket, and copy/deploy the images from github repo into the s3 bucket and change the permission to public readable.
  9. Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html

The entire infrastructure will be set up using Terraform

First of all we need to create IAM user with required privileges & note down the access key Id & secret access keys. We then need to configure AWS using this user as under

AWS Configure

Next step is to create a key-pair using below code

Key-pair

Create VPC and VPC Subnet, Internet gateway, Route table

VPC , Subnet & IGW
security group

Now, we’ll set up an EC2 instance using Amazon Linux AMI with instance type t2.micro

Launch EC2 instance

Create EFS volume using the EFS service and attach EFS to VPC and Instance.

EFS Volume creation

We need to mount the EFS volume to /var/www/html directory so that all the files are permanently stored in EFS.

Mount EFS Volume

Next step is to create S3 bucket, upload image to S3 bucket and grant public access to images

S3 bucket creation & image upload

Cloud Front Set up

Cloud Front Set up

We are all set to set up the entire Infrastructure on AWS using commands as shown below

Terraform Init

Terraform Apply command to apply the changes

We can see that EC2 instance launched with the key-pair & security groups in specified region

EC2 Instance Launch

Security Group

Security Group

EFS Volume created as under

EFS Volume

S3 bucket also gets created

S3 bucket created
Image uploaded into S3 bucket

--

--

Arvind Ramugade

Cloud Professional experienced in BFSI ,Telecom, Insurance domain with fortune 500 clients spread across USA, Europe, Canada, Australia and India.