Launch Application On AWS With EFS Using Terraform-
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Amazon Elastic File System (EFS) provides scalable file storage for use with Amazon EC2. We can create an EFS file system and configure our instances to mount the file system. We can use an EFS file system as a common data source for workloads and applications running on multiple instances.
Task : Create/Launch Application using Terraform-
1. Create 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. Developer have uploaded the code into github repo also the repo has some images.
6. Copy the github repo code into /var/www/html
7. Create 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.
Follow these steps:-
Step1 - In the very first step, we have to create a Key-Pair using terraform code.
Step 2 - After that we have to create a security group for launcing EC2 instance by using terraform code.
Step 3 - We have to launch an EC2 instance using the key-pair and security group created by us in the previous steps.
Step 4 - We have to launch volume by using EFS and then we have to mount it into /var/www/html.
Step 5 - Here, we have to create an S3 bucket and upload the images from Github repository to the S3 bucket using terraform code and make it public readable.
Step 6 - Now, create a Cloudfront using S3 bucket (which contains images) and use the Cloudfront URL to update in code in /var/www/html.
Step 7 - Now when we type the cloudfront url followed by the image url then we will see something like -
Step 8- Now launch the website using the below code:-
Step 9 - Destroy the complete environment using the command-
Thanks for giving your valuable time in reading the article!!
For the full code, go to my Github Repo using the link given below -https://github.com/Megha-Varshney/AWS_EFS/blob/master/file1