High Availability Structure in AWS using CloudFront
Let's discuss some basics first.
What is Cloud Computing?
Cloud computing is the on-demand availability of computer system resources, especially data storage (cloud storage) and computing power, without direct active management by the user. The term is generally used to describe data centers available to many users over the Internet. It doesn't store any data on the hard disk of your personal computer. In cloud computing, you can access data from a remote server.
What is AWS ?
Amazon Web Services (AWS) is the world's most comprehensive and broadly adopted cloud platform, offering over 175 fully featured services from data centers globally. Amazon web service is a platform that offers flexible, reliable, scalable, easy-to-use and cost-effective cloud computing solutions. AWS is a comprehensive, easy to use computing platform offered Amazon.
What is EC2 ?
Amazon Elastic Compute Cloud(EC2) is a part of Amazon's cloud-computing platform, Amazon Web Services, that allows users to rent virtual computers on which to run their own computer applications. It is a virtual server in for running applications on the Amazon Web Services (AWS) infrastructure. EC2 is a service that allows business subscribers to run application programs in the computing environment.
What is EBS ?
AWS Elastic Block Store (EBS) is Amazon's block-level storage solution used with the EC2 cloud service to store persistent data. This means that the data is kept on the AWS EBS servers even when the EC2 instances are shut down.
What is S3 ?
Amazon Simple Storage Service(S3) is a service offered by Amazon Web Services that provides object storage through a web service interface. Amazon S3 uses the same scalable storage infrastructure that Amazon.com uses to run its global e-commerce network. It offers industry-leading scalability, data availability, security, and performance.
What is CloudFront ?
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. Content delivery networks provide a globally-distributed network of proxy servers which cache content, such as web videos or other bulky media, more locally to consumers, thus improving access speed for downloading the content.
CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you're serving with CloudFront, the user is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.
What does High Availability Structure mean ?
High Availability systems are dependable enough to operate continuously without failing. They are well-tested and sometimes equipped with redundant components. They can be accessed anywhere in the world with low latency. Moreover, they also showcase high speed delivery of content.
---------------------------------------------------------------------------------------------------------------
Now, let's move on to practical part.
Step 1 : Download AWS CLIv2.
You can refer to this link: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html
Check whether successfully installed or not using aws --version command.
Step 2 : Configure AWS CLI in Windows CMD.
For configuring use command aws configure.
Step 3 : Create a new Key-pair.
- Initially there are only these key pairs in my aws account.
- Now, create a key pair by command : aws ec2 create-key-pair --key-name ANYNAME --output-text > ANYNAME.pem
- Now, a new key pair has been created in my account.
Step 4 : Create new Security Group and add inbound rules.
- Create a new security group using command : aws ec2 create-security-group --group-name ANYNAME --description "desc"
- Now, a new sg is created in my account.
- Add inbound rules to sg using command : aws ec2 authorize-security-group-ingree --group-name GroupName --group-id SG-Id --protocol tcp --port PortNo. --cidr 0.0.0.0/0
- Now, my sg have two inbound rules.
Step 5 : Launch a new EC2 instance.
- Launch a new EC2 Instance using command : aws ec2 run-instances --image-id ImageId --instance-type t2.micro --count 1 --security-group-ids SG-Id --key-name ANYNAME --subnet-id SUBNETId
- Now, a new instance is launched.
Step 6 : Create an EBS volume and attach it to the instance.
- Create an EBS Volume using command : aws ec2 create-volume --availability-zone ap-south-1a --size1 --volume-type gp2
- Now a new volume of 1 GB is created in my account.
- Now, attach this volume to instance using command : aws ec2 attach-volume --instance-id InstanceId --volume-id VolumeId --device /dev/sdh
- It is attached to my instance now.
Step 7 : Doing SSH Login to the instance via Windows.
- Use the highlighted command for your instance to do ssh login.
Step 8 : Configuring apache webserver on EC2 Instance.
- Install httpd server using command sudo yum install httpd -y
- Starting webserver service using sudo systemctl start httpd and checking status using sudo systemctl status httpd
Step 9 : Creating a partition and mounting it on /var/www/html folder.
- Check the available volumes using sudo fdisk -l
- Create a partition using sudo fdisk /dev/xvdh
- Format the partition using sudo mkfs.ext4 /dev/xvdh
- Mount the partition on /var/www/html folder using sudo mount /dev/xvdh /var/www/html
- Check using command df -h
Step 10 : Creating a S3 Bucket and storing static objects such as pictures
- Create a S3 bucket using command : aws s3api create-bucket --bucket ANYNAME --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1
- Now, my bucket is created.
- Putting an image in this S3 Bucket using command : aws s3 cp FILEPATHWITHNAME s3://BucketName/ --acl public-read-write
- Now, my image is uploaded in the bucket. Copy the Object URL to the image.
Step 11 : Creating a webpage and checking S3 image.
- Again login to your instance via ssh in the same way.
- Go to /var/www/html folder via command sudo cd /car/www/html
- Create a webpage using vi WebpageName.html
- Write a small html script and use the same URL which we copied from S3 Bucket.
- Open the webpage in browser using public IP of instance and name of webpage.
Step 12 : Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
- Create a new CloudFront Distribution using command : aws cloudfront create-distribution --origin-domain-name BucketName.s3.amazonaws.com
- Now, my distribution is created. Copy the domain name url.
Step 13 : Placing the Cloud Front URL on the Webpage code for security and low latency.
- Again login to your instance via ssh in the same way.
- Go to /var/www/html folder via command sudo cd /car/www/html
- Open the same webpage using vi WebpageName.html
- Replace the S3 URL with this CloudFront URL.
- Again open the webpage in browser using public IP of instance and name of webpage.
Now, you will see that the page will load much faster than earlier.
------------------------------------------------------------------------------------------------------------
In this way, we can use CloudFront to create a high availability structure with low latency and high security via AWS CLI.
Thank you !!