Terraform code To Launch Ec2 and Mount EFS In AWS Using Github.

What we do…

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. A 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 an 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


2. For Basic please refer my article listed below:-

How we do…

$ We create 3 subnets in this Newly created VPC.

$ We create one Internet gateway that provides the connection to our VPC.

$ We create one route table that connects our Subnet with the router.

$ Now we associate out route table with subnets.

$ We create one Security Group and allow port no 80 for HTTP, 22 for SSH, and 2049 for EFS.

$ We create one EFS storage where we store files. And we mount this in all the three subnets.

for mounting, we use efs mount target resources.

$ Now we create one instance which we launch in the above-created VPC. And install some necessary software which we use in further process.

$ We create one null resource. we use this resource to mount the EFS in /var/www/html folder.

$ We create one S3 bucket where we store our image. This image comes from Github and downloads temporarily in your system. Make sure your bucket name always be unique. Otherwise, it will not create.

$ Bucket_Object we use to store our file in the newly created bucket or already exist bucket. Here we declare the specification of our image which we store in this.

$ We create one cloud distribution. It will create one cache in your near edge location for 0 latency.

$ We create one more null resource which inserts the URL of the image in our PHP code.

“echo -n \”<img src=’http://${aws_cloudfront_distribution.s3_distribution.domain_name}/${aws_s3_bucket_object.object.key}'>\" >> /var/www/html/index.php”,

$ When you put your instance public IP then the output will display like this.

Thanks for reading. If you have any dought feel free to ask. I will reply as soon as possible….

B.Tech student and Researcher. Like To Study And Publish Article Related To New Technologies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store