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.
🔅Configuring webserver :
First create an ec2 instance using aws cli.For creating an instance we need a key,image id(AMI id) remaining options have default values like for instance-type ,default is m1.small
Here is how to configure awscli in command line
aws ec2 run-instances — image-id <AMI-id> — security-group-ids <sg-id> — key-name <ur key> — instance-type t2.micro — count 1
After starting the instance connect to it via any terminal emulator software like putty.Then
yum install httpd
systemctl start httpd
🔅Attaching an EBS volume:
Then attached an EBS volume to the created instance.
aws ec2 attach-volume — device /dev/xvdf — instance-id <id> — volume-id <vol-id>
🔅Mounting document root to EBS volume:
After connecting to the instance install httpd web server and mounted the /var/www/html to EBS volume.
Then transfer a static image to the instance using winscp and move the image to EBS volume (i:e /var/www/html)
🔅Creating a S3 bucket :
aws s3api create-bucket — bucket <name> — create-bucket-configuration LocationConstraint=<region(ap-south-1)>
aws s3 mb <bucket-name>
Then upload the files via cp,mv or sync commands
aws s3 cp<”local-path-to file”> <url of bucket>
🔅Creating Cloud Front web distribution:
Now create a cloud front web distribution as
aws cloudfront create-distribution — origin-domain-name [origin-domain(s3bucketname.s3.amazonaws.com)] >file_name
🔅Configuring webapp for low latency and security:
Now we can use all the static files stored in origin within the webapp along with distribution domain name to acheive low latency.