EC2 or Elastic Cloud Compute is the most popular AWS service.
EC2 consists of
Renting virtual machines (EC2s)
Storing data on virtual drives (EBS or Elastic Block Storage)
Distributing load across machines (ELB or Elastic Load Balancer)
Scaling EC2 services by using an auto-scaling group or ASG
EC2 Provisioning Considerations
You select an EC2 Instance Type, which specifies:
CPU power and cores
OS to deploy
– network attached eg EBS & EFS
– hardware attached ie EC2 Instance Store
Networking – speed of interface, public IP, subnet/s
Firewalling rules – security group
Bootstrap script for first bootup – “EC2 User Data” script – can do almost anything – eg update software, download files, configure or copy config or data files etc
NOTE the user data script runs with sudo root user.
Choosing an AWS Region
You will usually want to choose a region closest to your customers or users.
For price comparisons for AWS regions see https://instances.vantage.sh/ for precise info about ec2 options
and the AWS https://calculator.aws/#/
and https://www.instance-pricing.com/provider=aws-ec2/cheapest/ for cheapest regions
ap-south-1 Mumbai is cheap
Virginia, Ohio,Oregon and Mumbai are often the cheapest, London and Frankfurt more expensive.
N. Virginia is typically the cheapest region.
If you want to have the cheapest prices, best selection of products and highest number of Availability Zones, then N. Virginia tends to be best. This region is followed closely by Ireland, Oregon and Ohio.
Choosing any region outside of N. Virginia, Ireland, Oregon or Ohio means you could end up with only 2 AZs, probably pay more and may have to wait several weeks – even months – before new services are implemented in those regions.
EC2 Instance Type Naming Convention
m = instance class
5 = hardware generation – improves over time
2xlarge = size within the instance class
price will obviously vary according to instance type.
General purpose A1, T3, T3a, T2, M6g, M5, M5a, M5n, M4
Compute optimized C5, C5n, C4
Memory optimized R5, R5a, R5n, X1e, X1, High Memory, z1d
Accelerated computing P3, P2, Inf1, G4, G3, F1
Storage optimized I3, I3en, D2, H1
Securing Your EC2 Instance
You are responsible for configuring appropriate and effective access controls to protect your EC2 instances from unauthorized use.
Broadly speaking, AWS provides four tools to help you with this task:
Identity and Access Management (IAM) roles
network address translation (NAT) instances
You set hibernation in the EC2 Dashboard for the instance.
Then to activate hibernation click on “Instance State” -> hibernate
We have following options for EC2 Instances
Stop: data on EBS is kept intact for next start
Terminate: data on EBS is destroyed
First Start: OS boots, EC2 user data script runs
Subsequent Starts: OS boots
This however takes time…
With Hibernate however,
RAM in-memory state is preserved and boot is faster – OS state is frozen
this is written to a file in EBS volume -must have sufficient space and root
EBS volume must be encrypted. RAM is dumped to EBS.
for long running processes you dont want to interrupt or stop
saving the RAM state
services that take long time to initialize and start
RAM must be under 150GB
not available for bare metal instances
must be Linux or Windows os
AND – cannot be hibernated for more than 60 days!
This is a new virtualization tech for EC2 for the future.
better networking options
high performance computing
higher speed EBS volumes supported
types using Nitro: C5+, D G, M, instance types.
plus bare metal al.metal, c5.metal etc
multiple threads can run on 1 CPU. multithreading
each thread is called vCPU in AWS
is 4 CPU
2 threads per CPU
which makes 8 vCPU
the vCPU value does not specifiy the thread and CPU combination!
but in some cases you may want to decrease the number of vCPUs on your instance
eg to create more RAM and lower CPUs for software licensing costs
to change number of threads per core: you can disable multithreading which will mean 1 thread per CPU, which is helpful for hpc computing workloads
EC2 Capacity Reservations
ensure you have sufficient capacity available when needed-
it is a short term reservation
immediate reservation, billing starts immediately on reservation
you specify instance type, which AZ – only 1 AZ per reservation, if you want eg 3 AZs then you need to specify 3 reservations.
you can combine with reserved instances and savings plans to cut cost.
AMI Amazon Machine Image
AMI is a customization of an EC2 instance
you add your own software, config, os, etc
faster boot/config because all the software is prepackaged
can be built for a specific region and can be copied across regions
you can launch EC2 instances from
a public AMI -provided by AWS
and we can also create our own AMIs but you have to make and maintain them yourself
or you can purchase AMIs in the AWS Marketplace made by others
you can also sell AMIs yourself in the marketplace
The AMI Process from an EC2 perspective
we start an EC2 instance and customize it
then stop the instance – to ensure data integrity
we create an AMI of the instance – and this also creates EBS snapshots
we launch instances from our AMI
so, in detail:
create an EC2 instance, select type, network etc, add storage, some advanced details, including user data script.
then you create the AMI image using the EC2 dashboard, this takes a little time then it will be listed under ami images.
you can then use the image to create additional new EC2s – ie it serves as a full template instance.