High Availability Architecture with AWS CLI

High Availability Architecture with AWS CLI

To get started with creating a high availability architecture on AWS via the CLI, configure AWS CLI on your command prompt. To setup AWS CLI:

Install the AWS CLI installer package from the internet. Now, go to your CMD and type:

aws configure


The AWS CLI prompts you for four pieces of information. These information are stored in a profile (a collection of settings) named default in the credentials file. By default, the information in this profile is used when you run an AWS CLI command that doesn't explicitly specify a profile to use. Create an IAM user and enter these details

No alt text provided for this image

Thus, you are done with the setup!

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 webapp code for security and low latency.

1.Configuring the Webserver on EC2 instance:

Login into the instance launched on AWS as:

>ssh -l ec2-user #public_ipaddress -i #keyname.pem     //-l=login, -i=identity

Get the latest bug fixes and security updates by updating the software on your EC2 instance. To do this, use the following command.

sudo yum update 
No alt text provided for this image

After the updates complete, install the Apache web server.

sudo yum install httpd
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Start the web server with the command:

sudo systemctl start httpd

No alt text provided for this image
No alt text provided for this image

To test if your web server is properly installed and started, enter the public Domain Name System (DNS) name/public IPv4 Address of your EC2 instance in the address bar of a web browser. If your web server is running, then you see the Apache test page as:

No alt text provided for this image

The Apache test page appears only when there is no content in the document root directory, /var/www/html. After you add content to the document root directory, your content appears at the public DNS address of your EC2 instance instead of the Apache test page.

If you don't see the Apache test page, check your inbound rules for the VPC security group. Make sure that your inbound rules include a rule allowing HTTP (port 80) access for the IP address you use to connect to the web server. Use the security group id that you get at the time of security group creation to add ingress rules.

No alt text provided for this image

Add port 80 to the security group via cmd as:

No alt text provided for this image

Thus, your web server is configured.

2. Document Root(/var/www/html) made persistent by mounting on EBS Block Device.

The next step is to attach an EBS Volume to the /var/www/html folder to make the data persistent. For an EBS(Elastic Block Storage) volume to be attached to an instance, it must be in the same region as the instance. To find the availability zone of the instance, type:

aws ec2 describe-instances
No alt text provided for this image

Since the instance is created in ap-south-1b. Create the volume as:

aws ec2 create-volume --availability-zone ap-south-1b --size 1


No alt text provided for this image
No alt text provided for this image

 Attach the above created EBS volume to the instance.

aws ec2 attach-volume --device /dev/sdf --instance-id i-098dc4ca23b6561ed --volume-id vol-0653b89c63db38337


No alt text provided for this image

Now that the volume is attached to the instance, we can remotely login into the instance:

To login:

ssh -l ec2-user #public_ipaddress -i #Keyname.pem
(-l = login, -i = identity)
No alt text provided for this image

To make the newly attached volume available for use:

Create Partition:

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Format Partition:

No alt text provided for this image

Mount Partition:

mount /dev/xvdf1 /var/www/html
No alt text provided for this image
No alt text provided for this image

/dev/xvdf1 is a persistent storage that is linked to /var/www/html. Now when you enter the public Domain Name System (DNS) name/public IPv4 Address of your EC2 instance in the address bar of a web browser, you see the web page put in the /var/www/html. Whatever data you have in the /var/www/html folder gets its space from this partition(/dev/xvdf1).

No alt text provided for this image
No alt text provided for this image

3. Static objects used in code such as pictures stored in S3

Amazon Simple Storage Service is storage for the Internet. It is a global service and can be used to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.

A bucket is a container for objects stored in Amazon S3. Every object is contained in a bucket. For example, if the object named photos/puppy.jpg is stored in the awsexamplebucket1 bucket in the US West (Oregon) Region, then it is addressable using the URL https://awsexamplebucket1.s3.us-west-2.amazonaws.com/photos/puppy.jpg.

Bucket names must be globally unique (unique across all of Amazon S3) and should be DNS compliant.

Amazon S3 terms:

  • Bucket – A top-level Amazon S3 folder.
  • Prefix – An Amazon S3 folder in a bucket.
  • Object – Any item that's hosted in an Amazon S3 bucket.

To create a S3 bucket from the CLI,

aws s3 mb s3://mybucket --region 

The mb command creates a bucket, mybucket in a region specified by the --region parameter(optional). The bucket is created in the region specified in the user's configuration file.

No alt text provided for this image
No alt text provided for this image

To upload a file into S3, you’ll need to provide two arguments (source and destination) to the aws s3 cp command.

For example, to upload the file D:\ to the root of the kajal043 bucket, you can use the command below.

aws s3 cp (source_path) (destination_path) --acl public-read

Note: S3 bucket names are always prefixed with S3:// when used with AWS CLI

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

4. Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket. 

A Content Delivery Network(CDN) is a critical component of nearly any modern web application. It used to be that CDN merely improved the delivery of content by replicating commonly requested files (static content) across a globally distributed set of caching servers. However, CDNs have become much more useful over time. For caching, a CDN will reduce the load on an application origin and improve the experience of the requestor by delivering a local copy of the content from a nearby cache edge, or Point of Presence (PoP).

To create a distribution in cloudfront using the origin domain name as S3:

aws cloudfront create-distribution --origin-domain-name  #bucketname.s3.amazonaws.com
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

5. Finally place the Cloud Front URL on the webapp code for security and low latency.

The last step is to create a HTML code in an instance and specify the cloudfront URL. Copy the domain name:

No alt text provided for this image

Hit the public IPv4 address on the web browser to access the image via the cloudfront URL:

No alt text provided for this image

Hope you had a wonderful read!

Any suggestions/feedback regarding improvement of the article will be cordially acknowledged.














要查看或添加评论,请登录

Kajal .的更多文章

  • Getting Started with AWS CLI

    Getting Started with AWS CLI

    The AWS Command Line Interface (AWS CLI) is an unified, open source tool that enables you to interact with AWS services…

    4 条评论
  • Launch an Application on AWS using Terraform.

    Launch an Application on AWS using Terraform.

    In the journey of the blog, we'll see how to setup an automated AWS infrastructure using Terraform, using AWS services…

  • Deploy a kubernetes cluster on AWS-EKS.

    Deploy a kubernetes cluster on AWS-EKS.

    Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed service that makes it easy for you to run Kubernetes…

    2 条评论
  • Automated AWS Infrastructure with Terraform:EC2, EBS, S3,CloudFront + Github

    Automated AWS Infrastructure with Terraform:EC2, EBS, S3,CloudFront + Github

    Task: Have to create/launch Application using Terraform 1. Create the key and security group which allow the port 80.

    1 条评论

社区洞察

其他会员也浏览了