EC2
Amazon’s third service – EC2
What is EC2?
Amazon elastic compute cloud is a web service that provides resizable compute capacity in the
cloud.
EC2 reduces the time required to obtain and boot new server instances to minutes, allowing you
to quickly scale capacity, both up and down, as your computing requirements change.
EC2 Pricing Models
On Demand
Allows you to pay a fixed rate by the hour with no commitment
Developer who can test and shut it down
Reserved
Provides you with a capacity reservation, and offer a significant discount on the hourly charge for an
instance. Contract Terms area 1 year or 3 years (insignificant discount, the more you pay upfront, less it
costs)
Spot
Enables you to bid whatever price you want for instance capacity, providing for even greater savings if
your applications have flexible start and end times
Dedicated Hosts
Physical EC2 server dedicated for your use. Dedicated hosts can help you to use your existing server-
bound software licenses
1 is SQS, 2 is S3
EC2 - Region based – availability zone based
IAM – global based
S3 – Region based, but listed as global because the data is stored in over the regions
EC2 – Iaas Model
Launch EC2 Linux Instance
1. Choose an Amazon Machine Image
create an instance in GCP
azure create a virtual machine
An AMI is a template that contains the software configuration (operating system, application server, and
applications) required to launch your instance
Amazon Linux 2 comes with five years support. It provides Linux kernel 4.14 tuned for optimal
performance on Amazon EC2, systemd 219, GCC 7.3, Glibc 2.26, Binutils 2.29.1, and the latest software
packages through extras.
Instance - From an AMI, you launch an instance(vCPU, Memory, Instance Storage, EBS – Optimized
Available, N/W Performance, IPv6 Support), which is a copy of the AMI running as a virtual server in the
cloud.
Variable ECUs, 1 vCPUs, 2.5 GHz, Intel Xeon Family, 1 GiB memory, EBS only
Snapshot - A snapshot is of an EBS volume where you are able to save state and reboot with the same
data at a certain point in time. An AMI is similar, but its for the EC2 instances themselves. You cannot
take a snapshot of a non ebs backed instance, but you can create a AMI (system image) of one.
2. Choose an Instance Type
Instances are virtual servers that can run applications
They have varying combinations of CPU, memory, storage, and networking capacity, and give you the
flexibility to choose the appropriate mix of resources for your applications
EC2 Instances Limit
By default, AWS has a limit of 20 instances per region. This includes all instances set up on your AWS
account. To increase EC2 limits, request a higher limit by providing information about the new limit and
regions where it should be applied.
3. Configure Instance Details
On demand – Pay per hour
Regular project will go in on-demand
Spot – short time contract
Reserved – long time contract. (whenever model is changed to new, it will apply both prices)
Mask – though you launch (price will apply) and instant discard, it will not discard price
http://techgenix.com/aws-instance-purchase-models-explained/
without public ip, we cannot connect to the instance
Placement group
Cluster placement group
The strategy of the placement group determines how the instances are placed on underlying hardware.
A cluster placement group clusters instances into a low-latency group in a single Availability Zone.
(higher BW, there is no limitation in number of clusters)
A partition placement group spreads instances across logical partitions, ensuring that instances in one
partition do not share underlying hardware with instances in other partitions.
A spread placement group spreads instances across underlying hardware. (try not to have unique h/w,
one availability zone – only 7 can be launched, Security Content, Durability)
Addition of one more spread placement group – mother and child can be in same h/w in this case
Launch an instance in a placement group to benefit from greater redundancy or higher networking
throughput
Placement group:
Requirements for launching instances, in nearest H/W part.
If it is in same rack, one is failed, everything will fail.
When comes to hadoop, or performance, they will want the instance to be in same rack.
Capacity Reservation
Capacity Reservations reserve capacity for your EC2 instances in a specific Availability Zone. You can
launch instances into a Capacity Reservation if they have matching attributes (instance type, platform,
and Availability Zone), and available capacity.
Monitoring
For default 5 mins, detailed can be selected using cloud watch
Nagios,
Tenancy
You can choose to run your instances on physical servers fully dedicated for your use. The use of host
tenancy will request to launch instances onto Dedicated hosts (https://aws.amazon.com/ec2/dedicated-
hosts/), while the use of dedicated tenancy will launch instances as Dedicated instances
(https://aws.amazon.com/dedicated-instances/). You can launch an instance with a tenancy of host or
dedicated into a Dedicated VPC.ed –
T series
Enabling T2/T3 Unlimited allows applications to burst beyond the baseline for as long as needed at any
time. If the average CPU utilization of the instance is at or below the baseline, the hourly instance price
automatically covers all usage. Otherwise, all usage above baseline is billed.
User Data
Script – window – power
Linux - base script
You can specify user data to configure an instance or run a configuration script during launch. If you
launch more than one instance at a time, the user data is available to all the instances in that
reservation.
4. Add Storage
Instance Store can be added during launch, and not later
EBS volume can be attached to later, not during launch
Volume type
Cold hdd - temporary
5. Security Group
Firewall
A security group is a set of firewall rules that control the traffic for your instance. On this page, you can
add rules to allow specific traffic to reach your instance. For example, if you want to set up a web server
and allow Internet traffic to reach your instance, add rules that allow unrestricted access to the HTTP
and HTTPS ports.
6. Terminate Instance
Using AWS Management Console to Copy AWS EBS Volumes Between Regions
https://cloud.netapp.com/blog/ebs-volumes-5-lesser-known-functions
Connect to Linux Instance
1. Root user
2. System update
3. Install Apache server
4. Apache Server status check
5. Start Apache server
6. Stop Apache server
systemctl stop httpd
7. Navigate to html
8. Create html page
Vim index.html
:wq – to write and quit
9. Launch html page
10. Access Log for apache server
cat /var/log/httpd/access_log
cat /var/log/httpd/access_log | grep second.html
11. List other services of the AWS account
12. Configure Role for the user
13. Attach role to instance
14. List other services of the AWS account
i-05830c01ff1ca1107
ec2-13-232-196-53.ap-south-1.compute.amazonaws.com
Administrator
YR@l%XFwush*;*UbFM.BCEn?DZqzfrUT
Right click in Disk 1 and Disk 2 and give Online
Again right click on Disk 1 and Disk 2 and give Initialise disk
raid o for performance stripped volume
raid 1 for durablity mirror volume
EBS Volume and Instance Store
EBS Volume – The root device (operating device is installed) for an instance launched from the AMI is
an Amazon EBS Volume created from an Amazon EBS snapshot.
Instance Store Volume – The root device for an instance launched from the AMI is an instance store
volume created from a template stored in Amazon S3.
Load Balancing
High availability –
1. Classic Load Balancer
2. Network Load Balancer – Latency will be fast
Request is sent to Load Balancer and then it is sent to each instance with web server
Distribution and content delivery – this is achieved by Load Balancer
N/w – any port, it can be accessed
Load balancer name will be given in web address
3. Application level load balancer
Directory based
Sub domain based
Auto Scaling
1. Create Auto Scaling Group
2. Choose AMI
3. Select Launch configuration – Choose Instance Type
4. Configure Details
5. Add Storage
6. Configure Security Group
7. Review
8. Key pair Selection
9. Create AutoScaling Group
10. Configure Auto Scaling Group
11.
Snapshot
Snapshots only capture data that has been written to your amazon EBS volume at the time the snapshot
command is used.
AMI
AMI is a special type of virtual appliance that is used to instantiate a virtual machine within EC2. It serves
as the basic unit of deployment for services delivered using EC2.
Create Template
1. Create launch template
2. Launch Instance from template
Classic Load Balancer
1. Select Load Balance Type
2. Define Load balancer
3. Assign Security Group
4. Configure Security Groups
5. Configure health check up
6. Add EC2 Instances
7. Add Tags
7. Review
Target Group
1. Create Target group
2. Register Instances to TG
Application Load Balancer
AWS Lamba
Serverless computing - - Actions against a function, request is routed to server based on the action
Trigger based – pay only for the execution
RAM must be specified and execution cost can be achieved
Regional based
Scaling up means increasing the resources in terms of RAM such as 8 GB to 12 GB.
Scaling out means adding more and more instances.
Ex: Photo, dynamo DB content,
1. Select Region. Region based product
2. Create Lambda Function name, Select runtime program
3. Select micro level permissions
4. Configuration
5. Add Trigger
6. Select API Gateway
7. Select LambdaOne to create function in python
8. Select API Gateway
9. Delete ANY method
10. Create GET method
arn:aws:lambda:ap-south-1:462464466884:function:LamdaOne
11. Deploy API
https://74ing8zfx8.execute-api.ap-south-1.amazonaws.com/testing
12. URL Should be from Lambda function
13. Paste the execute API to index.html in S3 Bucket
14. Give Public access to the index.html
15. Enable Static website hosting in S3 bucket
http://maha312.s3-website.ap-south-1.amazonaws.com
16. Copy the python code to Lambda Function
17. Text is displayed on clicking the button
direct connect
vpn
data migration on permisises will not allow in public network