Terraform Basics Training Course
Terraform Provisioners
Introduction to AWS EC2 optional
In this article, we explore Amazon EC2, one of AWS's most popular services for running virtual machines in the cloud. EC2 instances—short for "Elastic Compute Cloud"—provide scalable compute resources that can be deployed in minutes. Like any physical or virtual computer, an EC2 instance runs an operating system (e.g., a Linux distribution or Windows) and can host software such as databases, web servers, and application servers.
AWS supplies pre-configured templates known as Amazon Machine Images (AMIs). These images include the operating system and any additional software configurations required for your EC2 instances. Popular AMIs include Ubuntu 20.04, RHEL 8, Amazon Linux 2, and Windows 2019.
Each AMI comes with an ID that is specific to the AWS region where you plan to deploy your instance. Additionally, EC2 provides various instance types, which are configurations combining CPU, memory, and networking performance tailored for specific workloads.
Instance Types Overview
For example, general purpose instance types offer a balanced mix for many common workloads. In contrast, compute-optimized types are ideal for high-performance CPU operations such as batch processing and data modeling, while memory-optimized types cater to applications that process large data sets in memory. For more details, consult the AWS Documentation.
General purpose instance types are subdivided into categories such as T2, T3, and M5, each available in various sizes to meet different requirements. For instance, the T2 Nano provides one virtual CPU and half a gigabyte of RAM, while the T2 Micro offers one vCPU and one gigabyte of RAM. Workloads requiring higher resources can select from sizes that range from small to 2xlarge, though these options vary among the different instance families.
Persistent storage for EC2 instances is managed by Amazon EBS (Elastic Block Storage). AWS currently offers five types of EBS volumes, including three high-performance SSD options and two cost-effective HDD alternatives. You can choose the storage type and size to attach to your instance during provisioning, and additional disks can be attached later if needed.
Another powerful feature of EC2 is the ability to pass user data during instance creation. This feature lets you execute configuration tasks or scripts automatically during startup. For instance, to install the Nginx package on an Ubuntu server, you can supply the following shell script as user data:
#!/bin/bash
sudo apt update
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
Similarly, Windows instances can be configured using PowerShell or BAT scripts.
Accessing EC2 Instances
After deployment, Linux EC2 instances are typically accessed via SSH keys, while Windows instances are accessed using Remote Desktop (RDP) along with the appropriate username and password.
In the upcoming demo, we will walk through the process of deploying a Linux EC2 instance using the AWS Management Console.
Watch Video
Watch video content