Kahibaro
Discord Login Register

Linux on AWS

Understanding How AWS Uses Linux

AWS is heavily built around Linux. Most compute and many managed services run some flavor of Linux under the hood. For you as a user, “Linux on AWS” mainly means:

This chapter focuses on what is specific about running and managing Linux in AWS, not on generic Linux administration or generic cloud concepts (covered elsewhere in the course).

Common Linux Options on AWS

Amazon Linux

Amazon Linux is AWS’s own distro, optimized for AWS:

Typical use cases:

Key specifics:

Other Popular Linux Distributions on AWS

AWS offers many official AMIs (Amazon Machine Images):

You select the distro at instance launch time by choosing the appropriate AMI.

Things that are AWS-specific:

Launching Linux EC2 Instances (What’s Unique)

Although starting a Linux instance is GUI-driven in the AWS console, what’s specific for Linux on AWS is:

AMIs (Amazon Machine Images)

An AMI is effectively a bootable template containing:

When you select an AMI:

For automation (CLI or IaC), AMI IDs look like:

Different regions have different AMI IDs even for the “same” image.

Instance Types and Linux

Linux supports the broadest selection of EC2 instance types. Two Linux-relevant aspects:

Linux kernels in the AMIs are built to support the corresponding virtualization environment (Nitro, ENA network driver, NVMe for EBS).

SSH Key Pairs

Linux instances are normally accessed with SSH keys:

Typical default usernames by distro:

SSH connection example:

ssh -i /path/to/key.pem ec2-user@ec2-203-0-113-10.compute-1.amazonaws.com

Because this is AWS-specific, you must:

EC2 Linux Networking and Security (AWS-Specific Angles)

Security Groups vs Local Firewalls

In AWS, security groups act as a virtual firewall at the instance’s network interface level.

Typical pattern for Linux on AWS:

Remember:

Elastic IPs and DNS

Linux instances often need stable IPs:

Preferred practice:

Instance Metadata and Credentials

Every EC2 instance can access its metadata via a special HTTP endpoint:

Example (Linux, via curl):

curl http://169.254.169.254/latest/meta-data/instance-id

This gives the instance ID, but more importantly, the metadata service is how:

You rarely query the credentials manually; instead, you:

aws s3 ls s3://my-bucket

The CLI fetches temp credentials from the metadata service automatically; no hard-coded keys needed.

Bootstrapping and Configuration: CloudInit & User Data

User Data

When launching a Linux instance, you can supply “user data”:

Example simple user data (bash script):

#!/bin/bash
yum update -y
yum install -y httpd
systemctl enable --now httpd
echo "Hello from AWS Linux" > /var/www/html/index.html

This is AWS-specific in that:

CloudInit Basics (AWS Perspective)

Most official Linux AMIs on AWS come with CloudInit configured.

CloudInit can:

YAML-style CloudInit example:

#cloud-config
packages:
  - nginx
users:
  - name: deploy
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    ssh_authorized_keys:
      - ssh-rsa AAAA...
runcmd:
  - systemctl enable --now nginx

Notes specific to AWS:

Storage: EBS and Instance Store from a Linux Perspective

EBS Volumes

EBS (Elastic Block Store) volumes show up as block devices in Linux, usually as:

AWS specifics:

Example: formatting and mounting an extra EBS volume in Linux:

# Check devices
lsblk
# Suppose /dev/nvme1n1 is the new EBS volume
sudo mkfs.ext4 /dev/nvme1n1
sudo mkdir -p /data
sudo mount /dev/nvme1n1 /data
# To persist across reboots, add to /etc/fstab:
echo '/dev/nvme1n1 /data ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab

Instance Store

Some instance types provide “instance store” (ephemeral storage):

Linux usage:

Snapshots and AMI Creation

From a Linux perspective:

Snapshot example from CLI (outside instance):

aws ec2 create-snapshot --volume-id vol-0123456789abcdef0 --description "Data volume backup"

You can also create a new AMI from a configured Linux instance:

Managing and Automating Linux on AWS

AWS CLI and SDK on Linux Instances

Linux hosts in AWS often run the AWS CLI:

Installation example on Amazon Linux 2:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Paired with an instance role, this lets the instance manage AWS resources, e.g.:

# List S3 buckets
aws s3 ls
# Query instance's own region
aws ec2 describe-instances --instance-ids "$(curl -s http://169.254.169.254/latest/meta-data/instance-id)" \
  --query 'Reservations[0].Instances[0].Placement.AvailabilityZone'

In DevOps workflows, Linux servers on AWS commonly:

AWS Systems Manager (SSM) and the SSM Agent

Systems Manager allows you to manage Linux instances without SSH:

Key Linux-focused features:

Example of starting a shell via SSM (from your local machine):

aws ssm start-session --target i-0123456789abcdef0

This is especially useful for hardened environments with no direct SSH access.

Logging and Monitoring with CloudWatch

Linux logs and metrics can be sent to AWS CloudWatch:

Configuration typically done via:

This enables:

Linux Containers on AWS (High-Level AWS-Specific Points)

A full containers chapter exists elsewhere; here’s what is AWS-specific:

Linux-specific concerns:

Security Considerations for Linux on AWS

Beyond generic Linux security, AWS-specific practices include:

Putting It Together: Typical Linux on AWS Workflow

A common real-world workflow for Linux on AWS might look like:

  1. Choose a Linux AMI (e.g., Amazon Linux 2023).
  2. Define:
    • Security group (SSH allowed only from office IP)
    • IAM role (e.g., S3 access, CloudWatch logging, SSM)
  3. Create a key pair (or rely on SSM + no SSH).
  4. Launch EC2 instance with:
    • User data script to install app dependencies
    • Appropriate storage (root + extra EBS volume)
  5. Log in via SSH or Session Manager and:
    • Verify services
    • Check /var/log/cloud-init.log for bootstrap issues
    • Configure application
  6. Create an AMI from this configured Linux instance for:
    • Autoscaling group
    • Quick environment recreation
  7. Attach CloudWatch Agent / logs and SSM for ongoing management.
  8. Use IaC tools (Terraform, CloudFormation, Ansible) to codify the above so future Linux environments are reproducible.

This chapter’s goal is to make those AWS-specific Linux behaviors and tools understandable so you can confidently operate Linux systems in AWS environments.

Views: 24

Comments

Please login to add a comment.

Don't have an account? Register now!