Hosting Website using Amazon EFS

Hosting Website using Amazon EFS

This is the extended part of task 1 here we will use EFS instead of EBS

Statement

1. Create a Security group that allows 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 task 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 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

We have implemented the whole scenario by using the terraform code.

We have implemented the whole scenario by using the terraform code.

Prerequisites-

  1. AWS Account https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/
  2. 2. Configure AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html
  3. It's recommended that we have an IAM User account https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html
  4. Terraform download = https://www.terraform.io/downloads.html
  5. AWS cliv2 download = https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html
  6. Use AWS configure (setup for AWS users in the AWS CLI)

Commands to run the code are:-

"terraform init" - it will initialize all the plugins.

"terraform plan" - it will create an execution plan.

"terraform apply --auto-approve" - the apply command is used to execute the plan and the -auto-approve option tells terraform not to require interactive approval of the plan before applying it.

"terraform destroy --auto-approve" - the destroy command is used to destroy the infrastructure and the -auto-approve option tells terraform not to require interactive approval of the plan before destroying it.

Proposed Solution-

First will configure the AWS

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

# We will create an S3 bucket

An Amazon S3 bucket is a public cloud storage resource available in Amazon Web Services' (AWS) Simple Storage Service (S3), an object storage offering. Amazon S3 buckets, which are similar to file folders, store objects, which consist of data and its descriptive metadata.

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Upload file to S3 Bucket

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Create a Cloudfront and attach it to S3 bucket

Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.

Code

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

Run “terraform apply --auto-approve”

No alt text provided for this image

#Create a VPC

Amazon Virtual Private Cloud (Amazon VPC) lets you provision a logically isolated section of the AWS Cloud where you can launch AWS resources in a virtual network that you define. You have complete control over your virtual networking environment, including the selection of your own IP address range, creation of subnets, and configuration of route tables and network gateways. You can use both IPv4 and IPv6 in your VPC for secure and easy access to resources and applications.

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Create a subnet in VPC

A subnetwork or subnet is a logical subdivision of an IP network. It is a range of IP addresses in your VPC. You can launch AWS resources into a specified subnet. If the user wants to launch an instance, directly user cannot launch an instance in Data Center they require subnet and while launching an instance they internally create a DHCP server.

Types of Subnet-

Public Subnet: A public subnet for resources that must be connected to the internet world

Private Subnet: A private subnet for resources that won't be connected to the internet.

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Creating a Security Group

Security Groups provide a modular way to define and compose firewall rules. The rules are managed at the hypervisor level in order to restrict incoming and outgoing network traffic. Ingress gateway operates at the edge of a service mesh, receiving incoming HTTP/TCP connections while configuring ports, protocols, and virtual services. Firewalls are designed to decline the request unless there are specific policy and configuration that allows ingress connections. Here according to our need, we have taken HTTP and SSH. By default, AWS creates an ALLOW ALL egress rule when creating a new Security Group inside of a VPC.

Code

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

Run “terraform apply --auto-approve”

No alt text provided for this image

#Creating an EFS(Elastic File Storage)

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.

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Mounting the EFS

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Add Internet Gateway to enable the instances in VPC to communicate with the outside world

An internet gateway is a horizontally scaled, redundant, and highly available VPC component that allows communication between your VPC and the internet. An internet gateway serves two purposes: to provide a target in your VPC route tables for internet-routable traffic and to perform network address translation (NAT) for instances that have been assigned public IPv4 addresses.

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Adding a Route Table

routing table contains a set of rules, called routes, that are used to determine where network traffic from your VPC is directed. You can explicitly associate a subnet with a particular route table. Otherwise, the subnet is implicitly associated with the main route table. Each route in a routing table specifies the range of IP addresses where you want the traffic to go (the destination) and the gateway, network interface, or connection through which to send the traffic (the target).

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Associating the Routing Table to Subnet

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

#Launching of EC2 Instance having the code in /var/www/html

Code

No alt text provided for this image

Run “terraform apply --auto-approve”

No alt text provided for this image

Copy Instance's Public DNS IP in browser to view our website

No alt text provided for this image

Now we are destroying the setup that we have created by using just one command

Run “terraform destroy --auto-approve”

No alt text provided for this image

Please find the code using the below link-

Thanks!!!!
From:
Adnan A. Shaikh



To view or add a comment, sign in

More articles by Adnan Shaikh

  • Configuring Docker Using Ansible

    Let’s see how we can configure an Apache Web Server on the top of Docker in any managed node with help of the Redhat…

    1 Comment
  • AWS Cloud Front configuration using AWS CLI

    AWS Development Tools Amazon has empowered the developers and architects to develop applications on AWS in the…

  • The Magic of AWS CLI

    We have seen Hollywood movies and Web series where a person tries to hack a system using CLI. But what is CLI? It is…

    1 Comment
  • Multi-Cloud Computing

    What is Multi-Cloud Computing? Multi-cloud (also multicloud or multi cloud) is the use of multiple cloud computing and…

    1 Comment
  • AWS VPC Security

    Statement 1. Write an Infrastructure as code using Terraform, which automatically creates a VPC.

  • Virtual Private Cloud (VPC)

    What is VPC? Amazon Virtual Private Cloud (Amazon VPC) lets you provision a logically isolated section of the AWS Cloud…

    2 Comments
  • Amazon EKS Fully managed Kubernetes Services

    What is EKS? Amazon Elastic Kubernetes Service (Amazon EKS) is a managed service that makes it easy for you to run…

  • The Future of Computing

    The goal of cloud computing is to allow users to take benefit from all of these technologies, without the need for deep…

Others also viewed

Explore content categories