Launching a Website using Elastic File Services in AWS
Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage, content delivery and other functionality to help businesses scale and grow. Running web and application servers in the cloud to host dynamic websites. Hence this proves to be the best way to provide IAAS (Infrastructure As A Service).
In this article we will see how to launch a website using various services like EC2 (Elastic Cloud Compute) ,EFS (Elastic File Services) ,S3 (Simple Storage Service) and Cloudfront.
We will first create a key and a security group which will be attached to an EC2 instance. Next we will install all the necessary frontend softwares inside it like HTTPD ,PHP ,Github and efs-utils. Then we will create an EFS volume which will attached to the instance and mounted on the folder /var/www/html. This folder contains the code for our website which is also downloaded from Github. After this we create the S3 bucket and upload the image downloaded from the Github and then create a Cloudfront Distribution of the bucket.
Lets get started with the complete process
- Downloading the necessary plugins for the provider - We run the terraform init command to initialize the environment and download the necessary plugins of the provider.
- Generating the new keypair - We then generate a keypair inorder to attach it to the instance and we also download the pem file of the keypair in the same folder.
- The downloaded key is in the folder.
- Creating a Security Group for Instance - We create a new Security Group for instance which allows SSH ,HTTP and EFS as the ingress rule inorder to have connectivity to the outside world and also to the EFS volume because the EFS volume can be accessed across availability zones hence we need to establish a connection with it too.
- Launching a new instance - Now we finally launch a new instance the above security group inside which we will download the necessary softwares.
- Installing necessary softwares - Now we attach the remote provisioner to access the EC2 instance through SSH using the key downloaded in the folder and then we install the HTTP AND GIT softwares. In addition to this we also install efs-utils. The amazon-efs-utils package comes with a mount helper and tooling that makes it easier to perform encryption of data in transit for Amazon EFS. A mount helper is a program that you use when you mount a specific type of file system. Hence we use the mount helper included in amazon-efs-utils to mount our Amazon EFS file systems.
- Creating an EFS volume - Next we will create a new EFS volume which depends on the creation of the instance.
- Attaching the EFS volume to the Instance - Next this volume will be mounted on the instance in which we have our website running this requires the file system id of the EFS created , the security group and subnet id of the instance which we have previously launched.
- Downloading the code from Github and mounting the volume to the instance - We will now download the code of our website from the Github directly inside the /var/www/html folder and mount the EFS volume to the same folder.
- Creating S3 Bucket - Now we create a S3 bucket in which we will upload the static content of our website. It has public-read permissions to allow the objects inside it to be accessed over internet in readable form. Hence giving it public access.
- Uploading the image in S3 - The static content of the website is an image which will be uploaded to the bucket so that the storage requirements are not high enough.
- Creating Cloudfront Distribution - Finally we create a Cloudfront Distribution of the S3 bucket so that it can be easily accessed over internet without any latency.
Terraform Validate command to check for any errors in the code.
Terraform Apply command to automatically create the complete infrastructure in just one click.
It will create all the resources.
Download all the necessary requirements and the softwares.
And finally launch the website.