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 Web App code for security and low latency.
What is the AWS Command Line Interface?
The AWS Command Line Interface (AWS CLI) is an open source tool that enables us to interact with AWS services using commands in our command-line shell. With minimal configuration, the AWS CLI enables us to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in our terminal program:
- Windows command line – On Windows, run commands at the Windows command prompt or in PowerShell.
WHAT IS IAM?
AWS Identity and Access Management (IAM) enables us to manage access to AWS services and resources securely. Using IAM, we can create and manage AWS users and groups, and use permissions to allow and deny their access to AWS resources.
WHAT IS KEY-PAIR?
A Key Pair consisting of a private key and a public key, is a set of security credentials that we use to prove our identity when connecting to an instance. We can use the private key, instead of a password, to securely access our instances.
WHAT IS SECURITY GROUP?
A Security Group acts as a virtual firewall for our EC2 instances to control incoming and outgoing traffic. Inbound rules control the incoming traffic to our instance, and outbound rules control the outgoing traffic from our instance. If we don't specify a security group, Amazon EC2 uses the default security group.
WHAT IS EC2 INSTANCE?
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows us to obtain and configure capacity with minimal friction. It provides us with complete control of our computing resources and lets us run on Amazon’s proven computing environment.
WHAT IS EBS VOLUME?
An Amazon EBS (Elastic Block Storage) Volume is a durable, block-level storage device that we can attach to our instances. EBS volumes persist independently from the running life of an EC2 instance.We can attach multiple EBS volumes to a single instance. The volume and instance must be in the same Availability Zone.
WHAT IS S3?
Object storage built to store and retrieve any amount of data from anywhere. Amazon Simple Storage Service (Amazon S3) is an object storage service that 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.
PRACTICAL PART:-
Step1- First of all, we have to create a IAM User whose credentials (Access Key and Secret Key) are used to communicate with the AWS via Windows CLI. Follow the steps given below for creating an IAM User.
- Click on Add User.
- Set Username and then select Programmatic Access that provides us an access key and secret key.
- Click on Attach existing policies directly and provide the AdministratorAccess to the user.
- Give the tag to the IAM User and then click on Review.
- Here, click on Download.csv.
- Now, we can see that the IAM user is created successfully.
Step2- Now, we have to install AWS CLI for the Windows. Then we have to use aws configure command. If this command is run with no arguments, then we will be prompted for configuration values such as our AWS Access Key Id and our AWS Secret Access Key and Default Region. This command helps us in login to the AWS via CLI after providing our access and secret key.
Step3- Create a Key-Pair using CLI.
Output:-
Step4- Create a Security Group for our instance and then add the specified ingress rules to the security group using CLI.
Output:-
Step5- Launch an EC2 Instance using the Key-Pair and the Security Group created by us in the previous steps.
Output:-
Step6- Create an EBS Volume using CLI.
Output:-
Step7- Attach the EBS Volume to the EC2 Instance created by us in the previous steps.
Output:-
Step8- Create a S3 bucket using CLI.
Output:-
Step9- Upload the Content to the S3 bucket using CLI and use the command to make the bucket and the content publicly accessible.
Output:-
Step10- Now use a command given below for login to the EC2 Instance.
ssh -i "AWS_KeyPair.pem" ec2-user@ec2-13-235-8-22.ap-south-1.compute.amazonaws.com
- First of all, install httpd software for configuring webserver inside the EC2 Instance. Then start the services.
- Use fdisk -l command to know how many Hard Disks are connected to the EC2 Instance.
- Use the steps given below to create the Partition inside the EBS Volume. Now, we can use that partition to store our data permanently.
- Create a partition using fdisk.
2. Format the Partition using mkfs.ext4 command.
3. Then, mount the partition to the /var/www/html/ folder using mount command.
Step11- Go inside the /var/www/html/ folder and then create a file.
Step12- Type Public_IP/File_Name on the Browser.
Step13- Create a CloudFront Distribution on the top of AWS using CLI.
Output:-
- Use CloudFront URL on the Browser:-
Step14- Now, give the CloudFront URL in place of S3 URL inside the file.html.
Step15- Again type Public_IP/File_Name on the Browser.