Set up Web Application with EFS on AWS cloud using Terraform

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

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

Create VPC and VPC Subnet, Internet gateway, Route table

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

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

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

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

Cloud Front Set up

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

Terraform Apply command to apply the changes

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

Security Group

EFS Volume created as under

S3 bucket also gets created

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