Deploy a web server on AWS Cloud using Terraform and EFS

Deploy a web server on AWS Cloud using Terraform and EFS

What is EFS?

Amazon Elastic File System (Amazon EFS) provides a simple, scalable, fully managed elastic NFS file system for use with AWS Cloud services and on-premises resources. It is built to scale on-demand to petabytes without disrupting applications, growing and shrinking automatically as you add and remove files, eliminating the need to provision and manage capacity to accommodate growth.

Objective of task:-

Create/launch Application using Terraform

1. Create a Security group which allow the port 80.

2. Launch EC2 instance.

3. In this Ec2 instance use the existing key or provided key and security group which we have created in step 1.

4. Launch one Volume using the EFS service and attach it in your vpc, then mount that volume into /var/www/html

5. The developer has uploaded the code into GitHub repo also the repo has some images.

6. Copy the GitHub repo code into /var/www/html

7. Create a S3 bucket, and copy/deploy the images from GitHub repo into the s3 bucket and change the permission to public readable.

8 Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html

Solution:-

Step 1: Configure the AWS CLI

No alt text provided for this image

Step 2: Creating the Key Pair

No alt text provided for this image
No alt text provided for this image

Our key pair is created i.e Mykey

Step 3: Create VPC

No alt text provided for this image
No alt text provided for this image

Our VPC is created i.e. myvpc.

Step 4: Create Subnet

No alt text provided for this image
No alt text provided for this image

Subnet is created i.e. mysubnet.

Step 5: Create internet gateway.

No alt text provided for this image
No alt text provided for this image

Internet gateway is created i.e. mygw.

Step 6: Create Route table.

No alt text provided for this image
No alt text provided for this image

Route Table is created i.e. myrtable.

Step 7: Now, Create the Security Group.

No alt text provided for this image
No alt text provided for this image

Security Group is created i.e. mysecuritygroup.

Step 8: Now create the EFS.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 9: Create the EC2 instances.

No alt text provided for this image
No alt text provided for this image

Step 10: Create the S3 bucket and put the object inside the S3 bucket.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 11: Now, Create the Cloudfront Distribution.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Now, our code is ready. We just run the cmd terrafrom apply. Before running this command we have to validate everything. For validate we have to run the cmd terraform validate.

So, Now everything is ready. Let see our final output.

No alt text provided for this image

After this we have to delete everything by running cmd terraform destroy.

No alt text provided for this image

Thank you for reading my article. If you face any problem or want to give any suggestion you are free to dm me.




To view or add a comment, sign in

More articles by Ritik Agarwal

Others also viewed

Explore content categories