Create High Availability Architecture with AWS CLI
✳️The architecture includes-
⭕ 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 webapp code for security and low latency.
Step 1:
Create an IAM user to access AWS CLI. Then use the following command to access the AWS service through CLI,
aws configure
Then create a key pair to launch an instance
aws ec2 create-key-pair --key-name <key_name>
Launching an instance.
aws ec2 run-instances --image-id <imageid> --instance-type <instancetype> --key-name <keyname> --security-group-ids <securitygroupid>
Step 2:
Create an EBS volume
aws ec2 create-volume --availability-zone <region_name> --size <size>
Attach an EBS volume to the launched instance,
aws ec2 attach-volume --instance-id <instance id> --volume-id <ebs volumeid> --device <device name>
Step 3:
Install Apache Server On The Instance
yum install httpd
Start the Service,
systemctl start httpd
Step 4:
Create a Partition on the attached EBS volume:
fdisk /dev/xvdf
Format the partition:
mkfs.ext4 /dev/xvdf1
Mount the Partition:
mount /dev/xvdf1 /var/www/html/ lsblk
Step 5:
Create a S3 Bucket,
aws s3api create-bucket --acl public-read-write --bucket <bucket name> --region <region name> --create-bucket-configuration LocationConstraint=<region name>
Upload your picture to the S3 Bucket
aws s3 cp <image name> <url>
Step 6:
Create a Cloud Front Distribution:
aws cloudfront create-distribution --origin-domain-name <s3 domain name>
Step 7:
Go to the path /var/www/html in your instance and create an .html file and add the cloud front URL in your script
Now lets take a look at our Web page
http://<instance ip>/filename.html
webpage is ready with great Security and Low latency
Thanks for reading
Good work