AWS EC2
Amazon Elastic Compute Cloud #
EC2 is a web service offered by Amazon Web Services (AWS) that provides resizable and scalable computing capacity in the cloud. In simple terms, AWS EC2 allows you to launch and manage virtual machines, known as instances, in the AWS cloud.
AWS EC2 is widely used for a variety of applications, including web hosting, data processing, machine learning, and more. It forms the foundation for many cloud-based solutions and allows businesses to rapidly deploy and manage virtual machines in the cloud without the need for physical hardware.
Scale Computing Resources #
EC2 instances can be easily scaled up or down based on your workload demands. This scalability ensures that you pay only for the compute capacity you use.
Instance Types #
AWS offers a variety of instance types optimized for different workloads, including general-purpose, compute-optimized, memory-optimized, and GPU instances.
AWS has over 700 instance types or combinations of CPU, memory, storage, networking, and specialized chips, offered as virtual or bare metal running Linux, Windows, or Mac operating systems.
Customize Instances #
Choosing the right instance can be challenging: cloud infrastructure and IaC make it possible to test different configurations and to change them over time, as requirements and usage become better known.
Check all the available options on the AWS Instance Type Details page.
Processor Architectures #
Instances are available in multiple processor architectures:
- x86 (64-bit Intel Xeon and AMD EPYC),
- ARM (64-bit AWS Graviton processors),
- Apple silicon (64-bit M1, M2 and later Mac instances).
Specialized Chips #
Additionally, instances can have specialized chips like
- AMD and NVIDIA GPUs,
- AWS Inferentia2 accelerators for deep learning (DL),
- AWS Trainium chips for deep learning training,
- AMD Xilinx FPGAs for custom hardware acceleration.
Secure and Manage Instances #
AWS provides features for managing and securing instances, including security groups, key pairs, and Identity and Access Management (IAM) roles and policies.
Load Balancing and Auto Scaling #
AWS services like Elastic Load Balancing (ELB) and Auto Scaling in conjunction with EC2 provide high availability and efficient scaling of applications.
Auto Scaling automatically adjusts the number of instances running an application based on real-time demand. Scaling policies use metrics such as CPU utilization, network traffic or custom application metrics that are constantly monitored: when the usage exceeds a threshold, AWS adds new instances and shares the load between them. When the load decreases, the additional instances are removed.
Data Storage Options #
AWS offers various storage options, including Amazon Elastic Block Store (EBS) for block storage and Amazon S3 for object storage, which can be attached to your EC2 instances.
Networking and VPC #
You can configure Virtual Private Cloud (VPC) networks and subnets to isolate and control the networking environment for the EC2 instances.
AMI Management #
EC2 instances are launched from Amazon Machine Images (AMIs), allowing to create, customize, and share pre-configured system images.
Monitoring and Management #
AWS provides tools like Amazon CloudWatch for monitoring and AWS Systems Manager for managing EC2 instances at scale.
Instance Lifecycle #
Most instances start in seconds in any AWS Region. They can also be hibernated, stopped, terminated, backed up or cloned by taking a point-in-time snapshot of the storage, with the instance running or stopped.
Purchasing Options #
- On-Demand: pay per second (Linux) or per hour, with no commitment.
- Savings Plans and Reserved Instances: a discount in exchange for a commitment of one or three years.
- Spot Instances: unused capacity at a large discount that AWS can reclaim with a two-minute notice, suitable for fault-tolerant workloads.
With Terraform #
EC2 instances are created with the resource aws_instance, or with a launch template and an Auto Scaling group for groups of instances. The AMI can be found with the aws_ami data source.
See tutorials:
More tutorials that use EC2
- AWS with Terraform Tutorial: AWS AMIs (11)
- Creating AWS EC2 Instances and Security Rules with Terraform (5/5)
- How to use Terraform, AWS, and Ansible Together
- AWS Route 53, AMI Lookup and EC2 Creation with Terraform (3/5)
- AWS with Terraform Tutorial: AWS Basics (2)
- Terraform AWS EKS Cluster Deployment & Application Publishing through ALB
- AWS and Terraform Naming Best Practices
- AWS VPC, Route 53, RDS MariaDB, EC2 using Ansible and Terraform (1/5)