Core AWS Services Compute and Storage
Now that you understand AWS's global infrastructure, let's explore the core services that run your applications and store your data. In this lesson, you'll learn about AWS's compute and storage services—the fundamental building blocks for virtually any cloud solution.
Learning Goals:
- Understand EC2 instances and their configuration options
- Learn about EBS volumes and S3 storage classes
- Deploy a simple web server using EC2
- Choose appropriate storage solutions for different use cases
Amazon EC2 (Elastic Compute Cloud)
Amazon EC2 provides resizable compute capacity in the cloud. Think of EC2 instances as virtual servers that you can launch in minutes.
EC2 Instance Types
AWS offers various instance families optimized for different workloads:
- General purpose (t3, m5): Balanced compute, memory, and networking
- Compute optimized (c5): High-performance processors
- Memory optimized (r5): Memory-intensive applications
- Storage optimized (i3): High, low-latency storage
Launching an EC2 Instance
Here's a basic example using AWS CLI to launch an EC2 instance:
#!/bin/bash
aws ec2 run-instances \
--image-id ami-0c02fb55956c7d316 \
--instance-type t3.micro \
--key-name my-key-pair \
--security-group-ids sg-903004f8 \
--subnet-id subnet-6e7f829e \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-server}]'
Always use the latest Amazon Machine Image (AMI) ID for your region. The AMI ID in the example is fictional—check the AWS Management Console for current AMI IDs in your region.
Amazon EBS (Elastic Block Store)
EBS provides persistent block storage volumes for use with EC2 instances. Unlike instance store volumes, EBS volumes persist independently from instance lifecycles.
Creating and Attaching EBS Volumes
#!/bin/bash
# Create a new EBS volume
VOLUME_ID=$(aws ec2 create-volume \
--availability-zone us-east-1a \
--size 20 \
--volume-type gp3 \
--query 'VolumeId' --output text)
# Attach to an EC2 instance
aws ec2 attach-volume \
--volume-id $VOLUME_ID \
--instance-id i-1234567890abcdef0 \
--device /dev/sdf
Amazon S3 (Simple Storage Service)
Amazon S3 is object storage built to store and retrieve any amount of data from anywhere. It's highly durable and scalable.
S3 Storage Classes
- Standard
- Infrequent Access
- Glacier
aws s3 cp large-file.zip s3://my-bucket/ \
--storage-class STANDARD
Use for frequently accessed data
aws s3 cp backup-file.tar.gz s3://my-bucket/ \
--storage-class STANDARD_IA
Use for less frequently accessed data (lower storage cost, higher retrieval cost)
aws s3 cp archive-file.iso s3://my-bucket/ \
--storage-class GLACIER
Use for long-term archives (very low storage cost, higher retrieval cost and time)
S3 Bucket Operations
#!/bin/bash
# Create a bucket
aws s3 mb s3://my-unique-bucket-name-123
# Upload a file
aws s3 cp local-file.txt s3://my-unique-bucket-name-123/
# List bucket contents
aws s3 ls s3://my-unique-bucket-name-123/
# Sync a directory
aws s3 sync ./my-website s3://my-unique-bucket-name-123/
S3 bucket names must be globally unique across all AWS accounts. If you get a "bucket already exists" error, try a different name.
Practical Example: Web Server with Persistent Storage
Let's combine EC2 and EBS to create a web server with persistent storage:
#!/bin/bash
# Launch EC2 instance
INSTANCE_ID=$(aws ec2 run-instances \
--image-id ami-0c02fb55956c7d316 \
--instance-type t3.micro \
--key-name my-key-pair \
--security-group-ids sg-903004f8 \
--user-data file://user-data.sh \
--query 'Instances[0].InstanceId' --output text)
# Wait for instance to be running
aws ec2 wait instance-running --instance-ids $INSTANCE_ID
# Create and attach EBS volume for web content
VOLUME_ID=$(aws ec2 create-volume \
--availability-zone us-east-1a \
--size 10 \
--volume-type gp3 \
--query 'VolumeId' --output text)
aws ec2 wait volume-available --volume-ids $VOLUME_ID
aws ec2 attach-volume \
--volume-id $VOLUME_ID \
--instance-id $INSTANCE_ID \
--device /dev/sdh
#!/bin/bash
# Update system and install web server
yum update -y
yum install -y httpd
# Start and enable web server
systemctl start httpd
systemctl enable httpd
# Create basic web page
echo "<h1>Hello from EC2!</h1>" > /var/www/html/index.html
Common Pitfalls
- Instance termination: Remember that EBS volumes persist by default, but instance store volumes are ephemeral and lost when instances stop/terminate
- Cost management: Leaving instances running when not needed can lead to unexpected charges—use auto-scaling or stop instances during off-hours
- Security groups: Misconfigured security groups are a common cause of connectivity issues—ensure proper inbound/outbound rules
- S3 permissions: New S3 buckets are private by default; you need to explicitly configure access permissions
- Volume types: Choosing the wrong EBS volume type (gp3 vs io2) can lead to performance issues or unnecessary costs
Summary
In this lesson, you learned about AWS's core compute and storage services. EC2 provides scalable virtual servers, EBS offers persistent block storage, and S3 delivers highly durable object storage. You practiced launching instances, creating storage volumes, and deploying a simple web application. Understanding when to use each service—and which configuration options to choose—is crucial for building efficient and cost-effective AWS solutions.
Quiz
AWS EC2 and S3 Fundamentals
Which EC2 instance family is optimized for memory-intensive applications?