Create High Availability Architecture with AWS CLI
Tejas Gupta
Building PW??★AWS Community Builder ★ Public Speaker ★ AWS/Azure/Redhat Certified ★Cloud & DevOps Engineer ★ AWS UG Mumbai ★ Content Creator
The article 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.
To Perform This Task You should have an aws account and an IAM user .
STEP 1:Download aws CLI and configure it.
STEP 2: START AN INSTANCE
COMMAND : aws ec2 start-instances --instance-ids <ID_OF_YOUR_INSTANCE>
STEP 3: Create an EBS volume and then attach it to the instance.
COMMAND TO CREATE AN EBS : aws ec2 create volume --availability-zone <AZ_CODE> --size <SIZE>
STEP 4 : Now attach the volume to the instance
COMMAND TO ATTACH AN EBS: aws ec2 attach-volume --volume-id <VOLUME_ID> --instance-id <INSTANCE_ID> --device <STORAGE_NAME>
Before using this attached volume , it must be partitioned and formatted first.
( here ssh program is used to login and run the command )
STEP 5 : PARTITIONING :
COMMAND TO CREATE PARTITION: ssh -i <KeyPair_Name> <USERNAME@IP> sudo fdisk <STORAGE_NAME>
n ( for new partition)
press enter (it will be first partition only)
press enter (it will be counting the space from initial sector)
w (save the partition and exit)
STEP 6 : FORMAT the partition with ext4 :
COMMAND : ssh -i <KEY_PAIR_NAME <USERNAME@IP> sudo mkfs.ext4 <PARTITION_NAME>
STEP 7 : Now Install httpd server using yum command
COMMAND : ssh -i <KEYPAIRNAME> <USERNAME@IP> sudo yum install httpd -y
STEP 8 : Start the httpd service:
COMMAND : ssh -i <KEYPAIRNAME> <USERNAME@IP> sudo systemctl start httpd
Check the status of the service:
COMMAND : ssh -i <KEYPAIRNAME> <USERNAME@IP> sudo systemctl status httpd
STEP 9 : Now , Mount the /var/www/html folder to the created partition of the EBS volume
COMMAND : ssh -i <KEYPAIRNAME> <USERNAME@IP> sudo mount <Partition_name> /var/www/html
To check the web server configuration create a small code and access it through the webUI
NOTE : save the code in /var/www/html directory.
STEP 10 : Create a S3 bucket and upload some objects there.
COMMAND : aws s3api create-bucket --bucket <Bucket_Name> --region <Region_code> --create-bucket-configurationConstraint=<region_code>
STEP 11 : Add an image as an object in the bucket.
STEP 12 : Now create a cloud Front distribution with the origin as above bucket .
COMMAND : aws cloudfront create-distribution --origin-domain-name <bucket_name>
STEP 13: Add the domain name of the cloud front distribution in the html file
Now open the web.html page in browser.
DevOps Engineer | Terraform/RHCSA/AWS/Azure Certified | AWS,Docker, Ansible, Kubernetes ,Terraform ,Python ,Jenkins,
4 年Nice info tejas ??