- Amazon EC2 is the virtual server instances on the AWS cloud.
- Amazon EC2 provides varying combinations of CPU, memory, storage, and networking capacity instance.
- EC2 AMIs are either backed by Amazon EBS or backed by instance store.
- You are limited to running On-Demand Instances per your vCPU-based On-Demand Instance limit.
- Amazon EC2 currently supports Amazon Linux, Ubuntu, Windows Server, Red Hat Enterprise Linux, SUSE Linux Enterprise Server, Fedora, Debian, CentOS, Gentoo Linux, Oracle Linux, and FreeBSD.
- You have full control at the operating system layer With EC2 instance.
- Key pairs are used to securely connect to EC2 instances:
- Ephemeral storage can be considered as non-persist or temporary storage.
- The contents of the instance store, or ephemeral storage will be lost on when instance is shut down ie; Data on any instance store volumes persists only during the life of the instance.
- Boot time for an instance on Amazon EBS-backed AMI is usually less than 1 minute.
- Boot time for an instance on Amazon instance store-backed AMI is usually less than 5 minutes.
- Size limit for a root device 16 TiB for Amazon EBS-backed AMI
- Size limit for a root device 10 GiB for Amazon instance store-backed AMI
- EC2 could attach Elastic Block Storage which allows for data persistence.
- For ephemeral storage, if the instance restarts, or the host experiences issues, you can incur data loss.
AWS EC2 userdata
- AWS userdata is the set of commands or data you can provide to execute in a instance at launch time.
- User data must be base64-encoded.
- User data will be run only once during instance start.
- User data will run with root user login.
- User data is limited to 16 KB in raw form, before it is base64-encoded.
- Instance metadata is data about your instance that you can manage the running instance.
- User data and metadata are not encrypted.
AWS EC2 On demand Instance:
- Pay for hours used : No commitment.
- Low cost and flexibility : No upfront cost.
- Ideal for auto scaling groups and unpredictable workloads.
- Good for Development/Adhoc Jobs / Testing
AWS EC2 Spot Instance :
- This will use unused EC2 capacity in the AWS cloud.
- Spot Instances are available at up to a 90% discount compared to On-Demand prices.
- Use Spot Instances for various stateless, fault-tolerant, or flexible applications such as big data, containerized workloads, CI/CD, web servers, high-performance computing (HPC), and other test & development workloads.
- Request Spot Instances by using the Spot management console, CLI, API or the same interface that is used for launching On-Demand instances by indicating the option to use Spot.
- You can also select a Launch Template or a pre-configured or custom Amazon Machine Image (AMI), configure security and network access to your Spot instance, choose from multiple instance types and locations, use static IP endpoints, and attach persistent block storage to your Spot instances.
- The Spot price is determined by long term trends in supply and demand for EC2 spare capacity.
- You don’t have to bid for Spot Instances in the new pricing model, and you just pay the Spot price that’s in effect for the current hour for the instances that you launch.
- Spot Instances receive a two-minute interruption notice when these instances are about to be reclaimed by EC2, because EC2 needs the capacity back.
- Instances are not interrupted because of higher competing bids.
- Each instance family, each instance size, in each Availability Zone, in every Region is a separate Spot pool.
- You can use the RequestSpotFleet API operation to launch thousands of Spot Instances and diversify resources automatically.
- To reduce the impact of interruptions, you can also set up Spot Instances and Spot Fleets to respond to an interruption notice by stopping or hibernating rather than terminating instances when capacity is no longer available.
AWS EC2 Reserved Instance:
- Purchase usage of EC2 instances in advance.
- Provides a capacity reservation when used in a specific AZ.
- AWS Billing automatically applies discounted rates when you launch an instance that matches your purchased Reserved instance.
- Capacity is reserved for a term of 1 or 3 years.
- EC2 has three types of reserved instance types: Standard, Convertible, and Scheduled.
- Standard Reserved instance : Commitment of 1 or 3 years, charged whether it’s on or off.
- Scheduled Reserved instance : Reserved for specific periods of time, accrue charges hourly, billed in monthly increments over the term (1 year).
- Convertible Reserved Instance : One-year to three-year term. Enables you to modify Availability Zone, scope, networking type, and instance size (within the same instance type) of your Reserved Instance.
- Scheduled Reserved instance match your capacity reservation to a predictable recurring schedule.
- Reserved instances are used for steady state workloads and predictable usage.
- Ideal for applications that need reserved capacity.
- Upfront payments can reduce the hourly rate.
- Can switch AZ within the same region.
- Can change the instance size within the same instance type.
- Instance type modifications are supported for Linux only.
- Cannot change the instance size of Windows RIs.
- Billed whether running or not.
- Can sell reservations on the AWS marketplace.
- Can be used in Auto Scaling Groups.
- Can be used in Placement Groups.
- Can be shared across multiple accounts within Consolidated Billing.
- You can try to sell them on the Reserved Instance Marketplace, if you are not using.
AWS EC2 Dedicated hosts:
- Physical servers dedicated just for your use.
- You then have control over which instances are deployed on that host.
- Available as On-Demand or with Dedicated Host Reservation.
- Useful if you have server-bound software licenses that use metrics like per-core, per-socket, or per-VM.
- Each dedicated host can only run one EC2 instance size and type.
- Good for regulatory compliance or licensing requirements.
- Predictable performance.
- Complete isolation.
- Most expensive option.
- Billing is per host.
AWS EC2 Dedicated instances:
- Virtualized instances on hardware just for you.
- Uses physically dedicated EC2 servers.
- Does not provide the additional visibility and controls of dedicated hosts.
- Billing is per instance.
- May share hardware with other non-dedicated instances in the same account.
- Available as On-Demand, Reserved Instances, and Spot Instances.
- Cost additional $2 per hour per region.
- Partial instance-hours consumed are billed based on instance usage.
Different type of IP that EC2 instance can have
- There are three types of IP address that can be assigned to an Amazon EC2 instance:
- Public IP– Public address that is assigned automatically to instances in public subnets and reassigned if instance is stopped/started.
- Private IP– Private address assigned automatically to all instances.
- Elastic IP – Public address that is static.
- Public IPv4 addresses are lost when the instance is stopped but private addresses (IPv4 and IPv6) are retained.
- Public IPv4 addresses are retained if you restart the instance.
- Elastic IPs are retained when the instance is stopped.
- Elastic IP addresses are static public IP addresses that can be remapped between instances.
- Accounts are limited to 5 elastic IPs per region by default.
- AWS charge for elastic IP’s when they’re not being used.
- An Elastic IP address is for use in a specific region only.
- You can assign custom tags to your Elastic IP addresses to categorize them.
- By default, EC2 instances come with a private IP assigned to the primary network interface (eth0).
- Public IP addresses are assigned for instances in public subnets (VPC).
- Public IP addresses are always assigned for instances in EC2-Classic.
- DNS records for elastic IP’s can be configured by filling out a form.
- Secondary IP addresses can be useful for hosting multiple websites on a server or redirecting traffic to a standby EC2 instance for HA.
- You can choose whether secondary IP addresses can be reassigned.
- You can associate a single private IPv4 address with a single Elastic IP address and vice versa.
- When reassigned the IPv4 to Elastic IP association is maintained.
- When a secondary private address is unassigned from an interface, the associated Elastic IP address is disassociated.
- You can assign or remove IP addresses from EC2 instances while they are running or stopped.
- All IP addresses (IPv4 and IPv6) remain attached to the network interface when detached or reassigned to another instance.
- You can attach a network interface to an instance in a different subnet as long as its within the same AZ.
Others
- Instance metadata is available at http://169.254.169.254/latest/meta-data/
- Instance user data is available at: http://169.254.169.254/latest/user-data.
- The IP address 169.254.169.254 is a link-local address and is valid only from the instance.
- To view metadata and userdata try this from your instance curl http://169.254.169.254/latest/meta-data/
- The Instance Metadata Query tool allows you to query the instance metadata without having to type out the full URI or category names.
- When you initiate hibernation, the instance moves to the stopping state. Amazon EC2 signals the operating system to perform hibernation (suspend-to-disk). The hibernation freezes all of the processes, saves the contents of the RAM to the EBS root volume, and then performs a regular shutdown.
Reference Pages
AWS EC2 Home page
EC2 Features
EC2 Instance Types
EC2 Instance Explorer