Sunday, 3 July 2022

Aws Ec2 Instance Theory

 

What is EC2 Instance?

  • It is a Computing resource that provides a virtual computing environment to deploy your application
  • In short, you can create a server on AWS and deploy your application on that server.

Why Use Amazon EC2?

  • No need for H/W, Develop and deploy the application faster.
  • Pay only for that you use
  • Auto scaling as per the workload.
  • Complete control of servers
  • Built-in security

EC2 Instance Types

  • General Purpose EC2 Instance
    • This type of instance is the most commonly utilised for testing. There are two types of general-purpose instances: “T” and “M.”
    • “T” instances are targeted to simple jobs just like testing environments, and they have a modest networking on the most basic options.
    • “M” Instances are for general use when you don’t want a testing environment, but you want an all-purpose instance. They offer more balanced resources compared to “T” instance
  • Compute Optimized
    • If your application requires to process a lot of information like math operations, load balancing, rendering task or sometimes video encoding
    • You need an instance that can process all that information in less time
  • Memory Optimized
    • If your app doesn’t require too much CPU, but instead, it needs more and faster RAM; you should check out the available option on the “X1e, X1 and R” instances.
  • Accelerated Computing
    • Creating a movie and need to render the textures? Need to design with power? Or you just have money to spend and want to play games on streaming?
  • Storage Optimized
    • This Kind of instances are provisioned with a more significant amount of TB for storage
    • You are going to have the best I/O Performance. These instances are a great option for those databases that need to be writing regularly on the disk, here we have three groups of instances: H, I and D.

Creating an EC2 instance

  1. Sign in to the AWS Management Console.
  2. Click on the EC2 service.
  3. Click on the Launch Instance button to create a new instance.

  4. Choose AMI: (Amazon Machine Image) AMI is a template used to create the EC2 instance.

  5. Choose Instance Type and then click on the Next. Suppose I choose a t2.micro as an instance type for testing purpose

  6. The main setup page of EC2 is shown below where we define setup configuration

  7. Never leave the default 8gb, if you want to be on the free tier limits you can set a value around 20gb -24gb, because sometimes you leave it as default and your instance is not going to have too many spaces to do many things, and click next

  8. Now, Add the Tags and then click on the Next.

  9. Configure Security Group. The security group allows some specific traffic to access your instance. i.e. If you want to have a web server you need to open port 80. If you want ssh access you need port 22, so let’s create a new one.

  10. Review an EC2 instance that you have just configured, and then click on the Launch button.

  11. Create a new key pair and enter the name of the key pair. Download the Key pair.
  12. Click on the Launch Instances button.

AWS EC2 Instance practical

Creating an EC2 instance

  1. Sign in to the AWS Management Console.
  2. Click on the EC2 service.
  3. Click on the Launch Instance button to create a new instance.



4.Choose AMI: (Amazon Machine Image) AMI is a template used to create the EC2 instance.





5.Choose Instance Type and then click on the Next. Suppose I choose a t2.micro as instance type for testing purpose.
6.The main setup page of EC2 is shown below where we define setup configuration.

                                                                                                                                     


7.Never leave the default 8gb, if you want to be on the free tier limits you can set a value around 20gb -24gb, because sometimes you leave it as default and your instance is not going to have too many spaces to do many things, and click next.

8.Now, Add the Tags and then click on the Next.




9.onfigure Security Group. The security group allows some specific traffic to access your instance. i.e. If you want to have a web server you need to open port 80. If you want ssh access you need port 22, so let’s create a new one.







10.Review an EC2 instance that you have just configured, and then click on the Launch button.







11.Create a new key pair and enter the name of the key pair. Download the Key pair.




12.Click on the Launch Instances button.













AWS S3 Theory

What is AWS S3?

Amazon Simple Storage Service (S3) is a storage for the internet. It is designed for large-capacity, low-cost storage provision across multiple geographical regions. Amazon S3 provides developers and IT teams with SecureDurable and Highly Scalable object storage.

S3 is Secure because AWS provides:

  • Encryption to the data that you store. It can happen in two ways:
    • Client Side Encryption
    • Server Side Encryption
  • Multiple copies are maintained to enable regeneration of data in case of data corruption
  • Versioning, wherein each edit is archived for a potential retrieval.

S3 is Durable because:

  • It regularly verifies the integrity of data stored using checksums e.g. if S3 detects there is any corruption in data, it is immediately repaired with the help of replicated data.
  • Even while storing or retrieving data, it checks incoming network traffic for any corrupted data packets.

S3 is Highly Scalable, since it automatically scales your storage according to your requirement and you only pay for the storage you use.

The next question which comes to our mind is,

What kind and how much of data one can store in AWS S3?

You can store virtually any kind of data, in any format, in S3 and when we talk about capacity, the volume and the number of objects that we can store in S3 are unlimited.

*An object is the fundamental entity in S3. It consists of data, key and metadata.

When we talk about data, it can be of two types-

  • Data which is to be accessed frequently.
  • Data which is accessed not that frequently.

Therefore, Amazon came up with 3 storage classes to provide its customers the best experience and at an affordable cost.

Let’s understand the 3 storage classes with a “health-care” use case:

1.Amazon S3 Standard for frequent data access 
standard storage - aws s3 tutorial - edurekaThis is suitable for performance sensitive use cases where the latency should be kept low. e.g. in a hospital, frequently  accessed data will be the data of admitted patients, which should be retrieved quickly.

 

2. Amazon S3 Standard for infrequent data access

This is suitable for use cases where the data is long lived and less frequently accessed, i.e for data archival but still expects high performance. e.g. in the same hospital, people who have been discharged, their records/data will not be needed on a daily basis, but if they return with any complication, their discharge summary should be retrieved quickly.

3.Amazon Glacier
Glacier - aws s3 tutorial - edureka
 Suitable for use cases where the data is to be archived, and high performance is not required, it has a lower cost than the other two services.e.g. in the hospital, patients’ test reports, prescriptions, MRI, X Ray, Scan docs etc. that are older than a year will not be needed in the daily run and even if it is required, lower latency is not needed.

Specification Snapshot: Storage Classes

s3 storage classes - aws s3 tutorial - edureka

How is data organized in S3?

Data in S3 is organized in the form of buckets.

Bucket s3 - aws s3 tutorial - edureka

  • A Bucket is a logical unit of storage in S3.
  • A Bucket contains objects which contain the data and metadata.

Before adding any data in S3 the user has to create a bucket which will be used to store objects.

Where is your data stored geographically?

You can self-choose where or in which region your data should be stored. Making a decision for the region is important and therefore it should be planned well.

These are the 4 parameters to choose the optimal region –

  • Pricing
  • User/Customer Location
  • Latency
  • Service Availability

Let’s understand this through an example:

Suppose there is a company which has to launch these storage instances to host a website for the customers in the US and India.

To provide the best experience, the company has to choose a region, which best fits its requirements.

regions - aws s3 tutorial - edureka


Now looking at the above parameters, we can clearly identify, that N Virginia will be the best region for this company because of the low latency and low price. Irrespective of your location, you can select any region which might suit your requirements, since you can access your S3 buckets from anywhere.

Talking about regions, let’s see about the possibility of having a backup in some other availability region or you may want to move your data to some other region. Thankfully, this feature has been recently added to the AWS S3 system and is pretty easy to use.

Cross-region Replication

As the name suggests, Cross-region Replication enables user to either replicate or transfer data to some other location without any hassle.

This obviously has a cost to it which has been discussed further in this article.

CRR - aws s3 tutorial - edureka

How is the data transferred?

Besides traditional transfer practices that is over the internet, AWS has 2 more ways to provide data transfer securely and at a faster rate:

  • Transfer Acceleration
  • Snowball

Cloudfront - aws s3 tutorial - edurekaTransfer Acceleration enables fast, easy and secure transfers over long distances by exploiting Amazon’s CloudFront edge technology.

CloudFront is a caching service by AWS, in which the data from client site gets transferred to the nearest edge location and from there the data is routed to your AWS S3 bucket over an optimised network path. 


The
 Snowball is a way of transferring your data physically. In this Amazon sends an equipment to your premises, on which you can load the data. It has a kindle attached to it which has your shipping address when it is shipped from Amazon. 
When data transfer is complete on the Snowball, Snowball - aws s3 tutorial - edurekakindle changes the shipping address back to the AWS headquarters where the Snowball has to be sent. 

The Snowball is ideal for customers who have large batches of data move. The average turnaround time for Snowball is 5-7 days, in the same time Transfer Acceleration can transfer up to 75 TB of data on a dedicated 1Gbps line. So depending on the use case, a customer can decide.

Obviously, there will be some cost around it, let’s look at the overall costing around S3.

Free on AWS?”

Yes!  As a part of the AWS Free Usage Tier, you can get started with AWS S3 for free. Upon sign up, new AWS customers receive 5 GB of Amazon S3 standard storage, 20,000 Get-Requests, 2,000 Put-Requests, and 15GB of data transfer-out each month for one year.

Over this limit, there is a cost attached, let’s understand how amazon charges you:

How is S3 billed?

Though having so many features, AWS S3 is affordable and flexible in its costing. It works on Pay Per Use, meaning, you only pay what you use. The table below is an example for pricing of S3 for a specific region:

aws s3 billing - aws s3 tutorial - edureka

Source: aws.amazon.com for North Virginia region

Cross Region Replication is billed in the following way:

If you replicate 1,000 1 GB objects (1,000 GB) between regions you will incur a request charge of $0.005 (1,000 requests x $0.005 per 1,000 requests) for replicating 1,000 objects and a charge of $20 ($0.020 per GB transferred x 1,000 GB) for inter-region data transfer. After replication, the 1,000 GB will incur storage charges based on the destination region.

Snowball, there are 2 variants:

  • Snowball 50 TB : 200$
  • Snowball 80 TB:  250$

This is the fixed service fee that they charge.

Apart from this there are on-site, charges which are exclusive of shipping days, the shipping days are free.

The first 10 on-site days are also free, meaning when the Snowball reaches your premises from then, till the day it is shipped back, they are the on-site days. The day it arrives, and the day it is shipped gets counted as shipping days, therefore are free.

AWS LIGHTSAIL Practical

 

Step 1: Sign up for AWS

This tutorial requires an AWS account. Sign up for AWS, or sign in to AWS if you already have an account.

Step 2: Create a WordPress instance in Lightsail

Complete the following steps to get your WordPress instance up and running on Lightsail.

Note

For more information about creating an instance in Lightsail, see Creating an Amazon Lightsail instance in the Lightsail documentation.

  1. Sign in to the Lightsail console.

  2. On the Instances tab of the Lightsail home page, choose Create instance.

    Launching and configuring WordPress in Lightsail.
  3. Choose the AWS Region and Availability Zone for your instance.

    Launching and configuring WordPress in Lightsail.
  4. Choose your instance image.

    1. Choose Linux/Unix as the platform.

    2. Choose WordPress as the blueprint.

      Launching and configuring WordPress in Lightsail.
  5. Choose an instance plan.

    A plan includes a low, predictable cost, machine configuration (RAM, SSD, vCPU), and data transfer allowance. You can try the $3.50 USD Lightsail plan without charge for one month (up to 750 hours). AWS credits one free month to your account.

    Note

    For a limited time, Lightsail is extending its free tier to include three months free on select instance plans. The offer applies to new or existing AWS accounts who started using Lightsail on or after July 8, 2021. Offer only applies to one bundle per account. Standard charges apply after the first 750 hours of usage of the selected bundle each month.

    You can use the following instance plans free for three months:

    • Linux/Unix instance plans: $3.50 USD per month, $5 USD per month, and $10 USD per month

    • Windows instance plans: $8 USD per month, $12 USD per month, and $20 USD per month

  6. Enter a name for your instance.

    Resource names:

    • Must be unique within each AWS Region in your Lightsail account.

    • Must contain 2 to 255 characters.

    • Must start and end with an alphanumeric character or number.

    • Can include alphanumeric characters, numbers, periods, dashes, and underscores.

    Launching and configuring WordPress in Lightsail.
  7. Choose Create instance.

Step 3: Connect to your instance via SSH and get the password for your WordPress website

The default password to sign in to the administration dashboard of your WordPress website is stored on the instance.

Complete the following steps to connect to your instance using the browser-based SSH client in the Lightsail console, and get the password for the administration dashboard.

Note

For more information, see Getting the application user name and password for your Bitnami instance in Amazon Lightsail

  1. On the Instances tab of the Lightsail home page, choose the SSH quick-connect icon for your WordPress instance.

    Launching and configuring WordPress in Lightsail.
  2. After the browser-based SSH client window opens, enter the following command to retrieve the default application password:

    cat $HOME/bitnami_application_password
  3. Make note of the password displayed on the screen. You use it later to sign in to the administration dashboard of your WordPress website.

    Launching and configuring WordPress in Lightsail.

Step 4: Sign in to the administration dashboard of your WordPress website

Now that you have the password for the administration dashboard of your WordPress website, you can sign in. In the administration dashboard, you can change your user password, install plugins, change the theme of your website, and more.

Complete the following steps to sign in to the administration dashboard of your WordPress website.

  1. In a browser window, go to:

    http://PublicIpAddress/wp-login.php

    In the address, replace PublicIpAddress with the public IP address of your WordPress instance. You can get your instance's public IP address from the Lightsail console as shown in the following example:

    Launching and configuring WordPress in Lightsail.
  2. In the Username or Email Address box, enter user.

  3. In the Password box, enter the default password obtained earlier in this tutorial.

  4. Choose Log in.

    Launching and configuring WordPress in Lightsail.

    You are now signed in to the administration dashboard of your WordPress website where you can perform administrative actions. For more information about administering your WordPress website, see the WordPress Codex in the WordPress documentation.

    Launching and configuring WordPress in Lightsail.

Step 5: Create a Lightsail static IP address and attach it to your WordPress instance

The default public IP for your WordPress instance changes if you stop and start your instance. A static IP address, attached to an instance, stays the same even if you stop and start your instance.

Complete the following steps to create a static IP address and attach it to your WordPress instance.

Note

For more information, see Create a static IP and attach it to an instance in Amazon Lightsail.

  1. On the Instances tab of the Lightsail home page, choose your running WordPress instance.

    Launching and configuring WordPress in Lightsail.
  2. Choose the Networking tab, then choose Create static IP.

    Launching and configuring WordPress in Lightsail.
  3. The static IP location, and attached instance are pre-selected based on the instance that you chose earlier in this tutorial.

    Launching and configuring WordPress in Lightsail.
  4. Name your static IP, then choose Create.

    Launching and configuring WordPress in Lightsail.

Step 6: Create a Lightsail DNS zone and map a domain to your WordPress instance

Transfer management of your domain's DNS records to Lightsail. This allows you to more easily map a domain to your WordPress instance, and manage more of your website’s resources using the Lightsail console.

Complete the following steps to create a Lightsail DNS zone and map a domain to your WordPress instance.

On the Networking tab of the Lightsail home page, choose Create DNS zone.

  1. Launching and configuring WordPress in Lightsail.
  2. Enter your domain, then choose Create DNS zone.

    Launching and configuring WordPress in Lightsail.
  3. Make note of the name server addresses listed on the page.

    You add these name server addresses to your domain name’s registrar to transfer management of your domain’s DNS records to Lightsail.

    Launching and configuring WordPress in Lightsail.
  4. After management of your domain’s DNS records are transferred to Lightsail, add an A record to point the apex of your domain to your WordPress instance, as follows:

    1. In the DNS zone for your domain, choose Add record.

    2. In the Subdomain box, enter an @ symbol to map the apex of your domain (such as example.com) to your instance. The @ symbol explicitly symbolizes that you’re adding an apex record. It is not added as a subdomain.

    3. In the Maps to box, choose the static IP that you attached to the WordPress instance in the previous step of this tutorial.

    4. Choose the save icon.

      Launching and configuring WordPress in Lightsail.

    Allow time for the change to propagate through the internet's DNS before your domain begins routing traffic to your WordPress instance.