Showing posts with label ec2. Show all posts
Showing posts with label ec2. Show all posts

Sunday, March 20, 2022

AWS Compute - Create a Launch Template for EC2 Instances


AWS - Create a Launch Template for EC2 Instances

A launch template function is that it specifies the instance's configuration information, such as:
  1. Amazon Machine Image (AMI)
  2. Instance type
  3. Key pair
  4. Security groups
  5. Other parameters used to launch EC2 instances.

Ways to create a Template and launching it

Step 1: Create an EC2 instance.

OS: Ubuntu 18.05
Instance type: t2.micro
Security Group: WebServer(port 22,80 are opened)
userdata:
#!/bin/bash
sudo su
sudo apt update
sudo apt install apache2 -y
sudo echo "<h1>Testing the Launch Template app </h1>" > /var/www/html/index.html

Step 2: Verify Instance get created with Apache installed and in the running state.

sudo su
systemctl status apache2
Take Public IP address of EC2 instance and check on browser.


Step 3: Create an AMI from EC2 instance.

Select EC2 instance
Action --> Image and Tempates ---> Image
Image: irfan/apacheimg

Step 4: Verify Image get created
Images ---> AMIs

Step 5: Create a Template from this image
Instances ---> Launch Template
Click on Create Template
Launch Template Name: ApacheTemplate
Template Version: Prod
Application and OS Images AMIs: irfan/apacheimg
Instance type: t2.micro
key pair: Irfan-RSA
Security Group: Webserver
Click on Create launch Tempate

Step 6: Create Ec2 instance from Template
Select the template ApacheTemplate
Action --> Launch Instance from template
Review the template settings
Launch Instance

Step 7: Verify the Instance is created and apache is installed with a modified index.html file

AWS Compute - EC2 Instances Information (General Purpose Type, Pricing Options)


SUMMARY:
1 - GENERAL PURPOSE TYPE OF EC2
2- EC2 INSTANCE PRICING OPTIONS


EC2 Instances - Elastic Compute Cloud

Amazon EC2 provides scalable computing capacity in the AWS cloud.
With EC2 instances you can configure security group, networking, and also manage storage.

EBS Storage and Instance store are two storage options.

By default, a maximum of 20 instances can only be created per Region and if needed to create more instances, then a request to the AWS support team need to be raised.


Types of EC2 Instances

  1. General Purpose:- Balance Memory and CPU
  2. Compute Optimized:- More CPU than RAM
  3. Memory-Optimized:- More RAM
  4. Storage Optimized:- Graphic Optimized
  5. Accelerated Computing:- Low Latency
  6. High Memory:- High Memory, Nitro System ( a type of hypervisor)
  7. Previous Generation


GENERAL PURPOSE TYPE:
It provides Balanced Memory CPU and networking resources and is well suitable for a variety of workloads. It is available in 4 sizes (Nano, small, Medium, Large).

There are 3 series in General purpose:
  1. A series
  2. M series
  3. T series

A Series (only has large size): It is well suited for the scale-out workloads that are supported by ARM Ecosystem (usually used for Robotic processes).

Below are well suitable use-cases for A-Series.
Webservers
Containerized Microservices
Caching fleets ( When you want to run multiple EC2 instances in parallel )
Distributed Data Store
The application that requires ARM Instruction set (
ARM is best known for its systems on a chip (SoC) , integrating on a single chip: microprocessor , graphics processing unit (GPU), DSP , FPU , SIMD , and peripheral controller . These are present in the majority of smartphones and tablets.)

M Series: It has M4, M5, M5a, M5ad, and M5d Instance types.
M4 Instance:- It features a Custom Intel Xeon E5-2676 v3 Haswell processor optimized specifically for EC2. It supports EBS Only Instance storage, vCpu 2 to 40(max), and RAM 8 GB to 160GB.
M5, M5a, M5ad, and M5d Instance:- These instances provide ideal Cloud infrastructure and offer a balance of compute, memory, and network resources for a broad range of applications. It supports EBS and NVMe SSD, vCpu 2 to 96(max), and RAM 8GB to 384 GB.

Below are the use cases:
Gaming Servers
Webservers
Small and Medium databases

T Series: t2, t3, t3a instance types
These instances are the baseline level of Cpu performance with the ability to burst to a higher level when required for your workload. It has vCpu 2 to 8 and RAM is 0.5GB to 32GB.

Below are the use cases:
Website and Web development
Code Repositories
Development Build and Test
Microservices


PRICING OPTIONS
OnDemand Instances 
Pay per second for the running instances.
The lifecycle of these instances can be controlled by you.
You can decide when to Start/Stop/Terminate/Hibernate/Reboot.
No long-term commitment is required.
The price per second is fixed.


Use Case:

For short term application
For an irregular workload that cannot be interrupted.


Reserved Instances (RI)
Amazon EC2 Reserved Instances (RI) provide a significant discount (up to 72%) compared to On-Demand pricing and provide a capacity reservation when used in a specific Availability Zone. If purchasing option for the EC2 instance is 1 year to 3 years then the Reserved Instance type is the best option. 
3 Payment options are available for RI:
  • Upfront
  • Partial upfront 
  • No Upfront
Reserved Instances are charged even there is no use.
Purchased RI is non-refundable.


Use Case:
For Long Term application
Discounted option as compared to On-Demand Instances.


Spot Instances
Spot Instance AWS Documentation
Because Spot Instances enable you to request unused EC2 instances at steep discounts, you can lower your Amazon EC2 costs significantly
The hourly price for a Spot Instance is called a Spot price.
Price is less than On-Demand Instances
These are selected on the basis of a bid that satisfies the requirement of EC2 instances.

How long do AWS spot instances last?
Regular spot pricing—instances can be terminated with 2 minutes notice. Defined duration—you can get a spot instance guaranteed to run for a period of 1-6 hours.

Use Cases:

Data Analytics
Batch jobs
Background processes




AWS Compute - EBS Volume (Snapshots and Volume Types)



EBS Volume Snapshots

Volumes are AZ specific means the volumes created in an AZ can be attached to EC2 instances which get created in that AZ

To utilize volumes in other AZ you need to create the snapshot of the volume and then create a new volume in the different AZ from the snapshot and attach to the instance which are available in different AZ

Copy the snapshots from one Region to another Region

When we create a volume from a snapshot then the size of volume can be increased but cannot be decreased.

We can create a root volume by taking a snapshot of the root volume of any instance.

EBS Volume Types

Amazon EBS provides the following volume types:
1. SSD
2. Provisioned IOPS SSD
3. Previous Generation HDD


1. Solid state drives (SSD)

Optimized for transactional workloads involving frequent read/write operations with small I/O size, where the dominant performance attribute is IOPS.
Solid state drives (SSD)
The SSD-backed volumes provided by Amazon EBS fall into these categories:

General Purpose SSD provides a balance of price and performance. We recommend these volumes for most workloads.

    gp3 (type of general purpose SSD): Durability:- 99.8% - 99.9% durability(0.1% - 0.2% annual failure rate)

    gp2 (type of general purpose SSD): Durability:- 99.8% - 99.9% durability(0.1% - 0.2% annual failure rate)

Use Case:

  • Low-latency interactive apps
  • Development and test environments
  1. Volume Size:   1 GB - 16 TB
  2. Max IOPS (input Output per Second) per volume (16 KiB I/O) : 16000
  3. Max throughput (data transfer) per volume: For gp3: 1,000 MB/s and for gp2: 250 MB/s*
  4. Amazon EBS Multi-attach(can attach multiple EBS volume): Not Supported
  5. Boot volume (OS system volume): Supported


2. Provisioned IOPS SSD
Provides high performance for mission-critical, low-latency, or high-throughput workloads. io2 Block Express a.k.a io2, io1 are the types of Provisioned IOPS SSD.

Durability: 99.999% durability (0.001% annual failure rate), for io1 - 99.8% - 99.9% durability (0.1% - 0.2% annual failure rate)

Use Case:
Workloads that require:
  • Sub-millisecond latency
  • Sustained IOPS performance
  • More than 64,000 IOPS or 1,000 MB/s of throughput
  1. Volume Size : 4 GB - 64 TB, for io1 - 4 GB - 16 TB
  2. Max IOPS per volume (16 KiB I/O) : 256,000 , for io1: 64,000
  3. Max throughput per volume : 4000MB/s, for io1: 1000/MiB/s
  4. Amazon EBS Multi-attach : Supported

3. Hard disk drives (HDD)
Optimized for large streaming workloads where the dominant performance attribute is throughput.

Use Cases:

  • Big data
  • Data warehouses
  • Log processing

1. Volume: 125 GB - 16 TB


4. Previous generation
Hard disk drives that can be used for workloads with small datasets where data is accessed infrequently and performance is not of primary importance. We recommend that you consider a current generation volume type instead.

Use Case:

  • Workloads where data is infrequently accessed

1. Volume size: 1GB to 1 TB


Thursday, March 10, 2022

ASSIGNMENT: AWS - Starting an EC2 instance with Security Group (for Port Forwarding)

Prerequisite:- A valid AWS account

IAM Permission: Min EC2 Full Access,EC2InstanceConnect

ChallengeDeploy a Website on an EC2 instance and should be accessible on Port 80. Below is the configuration for the website.

OS:-   ubuntu 18.04

Webserver: Apache

Firewall to open(Inbound): 22,80

Web Pages: HTML

Region: Select Region where you want to deploy the application.


Solution: Create an EC2 instance and install apache on top of it and attach a security group that has an inbound rule to open port number 22,80. Use public IP address to access the application on a browser.

Steps to Follow

Step 1:- Create a key-value pair (If you already have a valid public key (.pem or .ppk for putty then no need to perform this step)

  •   Click on Network & Security---> keypairs
  •   Click on Create a key pair button 
  •   Fill out the form by entering Name vdevops
  •   Key pair type:- RSA
  •   Private key format:- .pem
  •   Click on Create key pair. 
  •   Key should be listed in keypair list and a vdeops.pem file should be downloaded on your system ( keep it in some location in your computer so that we can refer it whenever it is required).

Step 2 Create Security Group (To open the firewall with defined port numbers). If you already created the security group then this step is optional.

  •    Select Network & Security--->Security Groups
  •    Click on Create Security Group Button 
  •     Fill out the form by entering below details
  •    Security Group Name: sgWebServer
  •    Description: Allow Http and SSH 
  •    No change in vpc value 
  •    Inbound rules:- Click on Add rule Button
                 select Type: SSH
                 source : AnyWhere-IPV4
  •     Click on Add rule Button
                 select Type: HTTP
                 source : AnyWhere-IPV4
  • Click on Create Security Group button 
  • Security Group should be created.


Step 3: Create an EC2 instance

  •   Search Service EC2 in the search box and select EC2 from the search list.
  •   Select Instances and Click on Launch Instances 
  •   Select AMI (Amazon Machine Image) - ubuntu 18.04
  •  Select Instance Type t2.micro and Click on Next Button
  •  Instance Details - Leave as it is because we are not making any change in VPC or subnet etc. On the Same page at the bottom select User Data and select As text and enter the below code.
#!/bin/bash
sudo su
sudo apt update
sudo apt install apache2 -y

  • Click on Next
  • Add Storage :- No Change
  • Click on Next
  • Add Tags:- Click on Add Tags button

            Key: Name
            value: WebServer

  • Click on Next
  • Configure Security Group
  • select the option :- select an existing security group
  • From the below list select sgWebServer
  • Click on Review and Launch
  • Review and Launch Page :- Click on Launch
  • select existing keypair :- vdevops
  • click on acknowledge checkbox and click on Launch Instances
  • On Launch Status Page Click on the view instances button
  • In the Instances list, you will find an EC2 instance which is WebServer
  • Wait for this instance to be in running status.


Step 4: Connect to EC2 Instance - WebServer

  • For Windows
  • Open MobaXterm Click on session---> SSH
  • Remote Host: public ip address of Ec2 instance
  • user name: ubuntu
  • Click on Advance SSH Settings
  • click on use Private key checkbox
  • select path for your vdevops key and click Ok Button
  • Terminal should be connected with EC2 instance

Step 5: Deploy Web page on this EC2 instance

  •  Login with root user :- sudo su
  • Check apache is already installed because we have mentioned apache installation script in USER DATA
  • systemctl status apache2
  • Create an index.html.
  •  echo "<h1>This is my first web page on AWS EC2 instance </h1>" > /var/www/html/index.html

Step 6: Visit the website on Browser

On Browser enter URL as PublicIP address of Webserver EC2 instance and you will be able to see the web page with above contents.


Few Experiments

  1. Stop EC2 instance and check that web page is opened or not
  2. Start EC2 instance and now again check the web page is getting opened or not
  3. Remove port number 80 from sgWebServer SG and check webpage is getting opened or not
  4. Add port number 80 from sgWebServer SG and check webpage is getting opened or not

Wednesday, February 16, 2022

Amazon EC2 Instances Intro




What is an Amazon Elastic Compute Cloud (EC2) instance?

An Amazon EC2 instance is a virtual server in Amazon's Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure. AWS is a comprehensive, evolving cloud computing platform; EC2 is a service that enables business subscribers to run application programs in the computing environment. It can serve as a practically unlimited set of virtual machines (VMs).

Amazon provides various types of instances with different configurations of CPU, memory, storage and networking resources to suit user needs. Each type is available in various sizes to address specific workload requirements.

Instances are created from Amazon Machine Images (AMI). The machine images are like templates. They are configured with an operating system (OS) and other software, which determine the user's operating environment. Users can select an AMI provided by AWS, the user community or through the AWS Marketplace. Users also can create their own AMIs and share them.

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...