Image for post
Image for post

Integrating various services of AWS using Terraform

Breaking our requirement into small steps for better understanding:

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 uploded 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

STEP1: Specifying Provider

We specify Terraform that we are going to use AWS as our cloud service provider and the user we are going to use. The user should be configured already in your system.

Image for post
Image for post

STEP2: Creating Security Group

The SG allows httpd to launch webserver, ssh so as to do remote login and allows efs .

Image for post
Image for post

STEP3: Launching instance(EC2)

The instance is launched with the key-pair (which is already created), add the SG, and lastly go inside the instance to download all the required services.

Image for post
Image for post

STEP4: Launching EFS and Mounting EFS

Launching EFS and mounting it in the /var/www/html folder of the instance as well as cloning the github repository into the same folder.

Image for post
Image for post

STEP5: Creating S3 bucket

S3 is a service which is used to store the static data . And setting the permission as public-read.

STEP6: Uploading on S3 bucket

Image for post
Image for post

STEP7: Creating CloudFront

CloudFront is the service that is provided by the AWS in which they create small data centres where they store our data to achieve low latency. It will create a CloudFront distribution using an S3 bucket. In this bucket, we have stored all of the assets of our site like images, icons, etc.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

STEP8: Generate Cloudfront URL for image and append to the HTML Page

Image for post
Image for post

Run the below command to download all the packages:

Image for post
Image for post

Then to check if there is any error or not run the below command:

If there is no error then run the comand

Image for post
Image for post

The webpage is:

Image for post
Image for post

After the complete setup to delete all the components in one click. Run the command:

Image for post
Image for post

The GitHub URL to the above task.

Thankyou.

Written by

I am a DevOps Enthusiast and recently taken to Cloud Computing. Learning Flutter App Development currently. In my free time I engage in competitive coding.

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