CREATE HIGH AVAILABILITY ARCHITECTURE WITH AWS CLI
Task Description
- Webserver configured on EC2 Instance
- Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
- Static objects used in code such as pictures stored in S3
- Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
- Finally, place the Cloud Front URL on the web app code for security and low latency.
Overview
What is AWS CLI?
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
To use AWS Cloud through CLI only Prerequisite is to Install the AWS CLI SDK tool.
Now let’s use AWS CLI, for this, we have to download AWS CLI in our base os.
Now let’s give AWS credentials, for this we need the access key and secret key these we will get while creating an IAM user in AWS.
aws configure
#to check whether we logged in
aws configure list
Creating key -pair
aws ec2 create-key-par --key-name mykey
by using this command you can create a key pair in cli
CREATE SECURITY GROUP
To create a Security group we have the command as :
aws ec2 create-security-group --group-name group_name --description "_description_"
We can also see the Information about Security Group in CLI using the command :
aws ec2 describe-security-group --group-id security_group_id
EC2:
An EC2 instance is nothing but a virtual server in Amazon Web services terminology. It stands for Elastic Compute Cloud. It is a web service where an AWS subscriber can request and provision a compute server in AWS cloud. AWS provides multiple instance types for the respective business needs of the user
CREATE INSTANCE
Now we have to Launch one EC2 Instance using the above Key pair and Security Group. To launch ec2 instance AWS CLI has command as :
aws ec2 run-instances --security-group-ids group_id --instance-type _type_ --image-id ami_id --key-name key_name --count no_of_instance
After Launching EC2 Instance now we have to create one EBS Volume and attach it to the EC2 Instance we launched.
CREATE EBS VOLUME
To Create EBS Volume AWS CLI has command as :
aws ec2 create-volume --volume-type volume_type --size volume_size --availability-zone AZ_name
To Attach EBS Volume to EC2 Instance we have command:
aws ec2 attach-volume --volume-id volume_id --instance-id instance_id --device device_name
now connect to the ec2 instance
run the following commands
suudo su -root
First, Install httpd software by yum command
yum install httpd -y
syystemctl start hhttpd
Let’s do partition, format, and mount our ebs volume so that new storage is added to our instance.
We will mount our new partition to /var/www/html
fdisk dev/xvdf #for partition
mkfs.ext4 /dev/xvdf1 #for fromat
mount /dev/xvdf1 /var/www/html
- Now let’s create an s3 bucket in the Mumbai region with some unique name.
aws s3 mb s3://nischal12345 --region ap-south-1
- Let’s upload an image in our bucket and make it public.
aws s3 cp (path of the image ) s3://taskstaticimages/pic.jpeg --acl public-read
- Let’s create a CloudFront with origin as an s3 bucket from the command line.
aws cloudfront create-distribution --origin-domain-name nischal12345.s3.amazonaws.com
- Let’s start httpd service and write a webpage for our webserver.
systemctl start httpd
# In webpage give cloudfront url
- The final step is to access our webpage.
# search instanceip/webpagename in google search engine
Connect me on my LinkedIn as well.