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
Step 2: Creating the Key Pair
Our key pair is created i.e Mykey
Step 3: Create VPC
Our VPC is created i.e. myvpc.
Step 4: Create Subnet
Subnet is created i.e. mysubnet.
Step 5: Create internet gateway.
Internet gateway is created i.e. mygw.
Step 6: Create Route table.
Route Table is created i.e. myrtable.
Step 7: Now, Create the Security Group.
Security Group is created i.e. mysecuritygroup.
Step 8: Now create the EFS.
Step 9: Create the EC2 instances.
Step 10: Create the S3 bucket and put the object inside the S3 bucket.
Step 11: Now, Create the Cloudfront Distribution.
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.
After this we have to delete everything by running cmd terraform destroy.
Thank you for reading my article. If you face any problem or want to give any suggestion you are free to dm me.