Sub topic 1
What EC2 is and what you are responsible for
Prerequisites
This chapter assumes you have the following:
- Basic Linux command-line skills.
- Basic networking concepts: IP addresses, CIDR blocks, and ports.
- An AWS account, and a basic idea of IAM users and permissions.
- Familiarity with SSH.
You do not need to have launched an EC2 instance before. Later chapters cover launching, securing, and operating instances step by step.
What EC2 provides
Amazon Elastic Compute Cloud (EC2) rents you virtual servers, called instances, on AWS hardware. You choose the operating system, the amount of CPU and memory, the storage, and the network placement. You can create an instance in minutes and delete it when you no longer need it. You pay for what you use, and AWS bills most instances per second while they run.
An instance is a virtual machine. AWS runs many virtual machines on one physical host, and a hypervisor keeps them separated. Current instance types run on the AWS Nitro System, which moves networking, storage, and security work onto dedicated hardware. This leaves more of the host's CPU and memory for your instance.
EC2 is called "resizable" because you can change capacity in two ways:
- Vertical: stop an instance and change its instance type to a larger or smaller one.
- Horizontal: run more instances and spread the work across them. The final chapters of this tutorial introduce this idea under Auto Scaling and load balancing.
The parts of an EC2 deployment
An instance is the center of a group of related resources. Each one gets its own chapter later, so this table is only a map.
| Part | What it does | Chapter topic |
|---|---|---|
| Region and Availability Zone | Decide the physical location of the instance | Regions and Availability Zones |
| AMI | The template the instance boots from | Choosing an AMI |
| Instance type | Sets CPU, memory, network, and storage capacity | Instance types and families |
| VPC and subnet | The private network the instance lives in | VPCs, subnets, and IP addresses |
| Security group | A virtual firewall around the instance | Security groups |
| Key pair | Lets you log in over SSH | Key pairs |
| EBS volume | Persistent disk storage | EBS volumes |
| IAM role | Gives software on the instance AWS permissions | IAM roles |
The shared responsibility model
AWS describes security as a shared responsibility. AWS is responsible for security of the cloud. You are responsible for security in the cloud. For EC2, which is an infrastructure-as-a-service product, you carry more of the second part than you would with a managed service.
| AWS is responsible for | You are responsible for |
|---|---|
| Physical data centers, power, and cooling | The guest operating system, including patches and updates |
| Host hardware and the hypervisor | Applications and software you install |
| The global network and the Regions and Availability Zones | Security group rules and network design |
| Replacing failed host hardware where possible | Who can log in, and how your keys and credentials are stored |
| The EC2 service and its APIs | IAM permissions, data encryption choices, and backups |
A concrete example shows where the line falls. If a disk in the data center fails, AWS handles the hardware. If you leave SSH open to the whole internet and use a weak account, that is your configuration, and AWS does not fix it for you.
What this means in practice
The responsibility split leads to a few habits you will build through the rest of the tutorial:
- Keep access narrow. Open only the ports you need, and only to the addresses that need them.
- Prefer roles to stored keys. Give software on an instance an IAM role instead of copying access keys onto the disk.
- Plan for failure. An instance can be stopped, terminated, or lost with its host. Keep important data on durable storage and take backups.
- Track cost. A running instance, an unused volume, and an unattached public IPv4 address can each add charges.
- Patch and replace. Update the operating system regularly, or rebuild instances from a fresh AMI.
Common mistakes
- Treating an instance as permanent. Instances are meant to be replaceable. If rebuilding one by hand would be painful, automate the build with user data or a custom AMI.
- Assuming AWS backs up your data. EC2 does not take backups unless you set them up. EBS snapshots are the standard tool, covered later.
- Confusing the console login with instance access. Your IAM user signs in to AWS. SSH access to the operating system uses a key pair or another method you configure.
- Working in the wrong Region. Resources are created in one Region. If an instance seems to be missing, check which Region the console or CLI is using.
Checking your setup
Before you launch anything, confirm that the AWS CLI works and which Region it will use. These two commands show who you are and where you will create resources.
aws sts get-caller-identity
aws configure get regionThe first command prints your account ID and the identity you are using. The second prints the default Region. If the second one prints nothing, set a Region with aws configure or pass --region on each command.
Looking ahead
The next chapters build the instance from the outside in. You first learn where it runs (Regions and Availability Zones), then what it boots from and how large it is (AMIs and instance types). After that you place it on a network, protect it, and connect to it. Only then do you launch it with the CLI.
Exercise
A teammate says, "AWS runs EC2, so AWS keeps our instance's operating system patched and our SSH rules safe." Which parts of that statement are wrong, and who is responsible for each?
Show answer
Both parts are wrong. With EC2 you are responsible for the guest operating system, including patching, and for security group rules and SSH access. AWS is responsible for the physical facilities, host hardware, hypervisor, and the underlying network. The line follows the rule that AWS secures the cloud, and you secure what you run in it.
Exercise
An instance in the Region you expected cannot be found by aws ec2 describe-instances, but you launched it yesterday. Name one likely cause and one command that helps you check it.
Show answer
The CLI may be using a different Region from the one where you launched the instance. Run aws configure get region to see the default Region, then repeat the query with --region set to the Region you used. Resources exist in one Region only.