Skip to content

Chapter 2 of 11

Compute: EC2 and Lambda

Choose between virtual machines and event-driven functions, then configure each safely.

42 minutes 10 quick checksBy Subha Prasad
Lesson 2 of 11Course navigation

Lesson content

Read, practise, then check your understanding

Compute: EC2 and Lambda

Amazon EC2 provides resizable virtual machines with control over operating systems, instance families, storage, networking, and placement. AWS Lambda runs short-lived event-driven code without server management. The right choice follows workload shape, control needs, execution duration, latency, and operating model.

Core ideas

  • An AMI defines the starting operating-system and software image for an EC2 instance.
  • An Auto Scaling group maintains desired capacity and can scale from demand or schedules.
  • EC2 instance profiles supply temporary IAM credentials without embedding access keys.
  • Lambda scales execution environments from events and charges primarily by requests and execution resources.

Design and operating model

Use EC2 for long-running services, specialized machine types, custom agents, or deep OS control. Use Lambda for event handlers, lightweight APIs, scheduled tasks, and bursty integration. For both, keep instances replaceable, place code in versioned artifacts, use roles, set limits, and emit structured telemetry.

Example

# Inspect available EC2 instances by tag
aws ec2 describe-instances \
  --filters 'Name=tag:Environment,Values=dev' \
  --query 'Reservations[].Instances[].[InstanceId,State.Name]'

# Invoke a deployed function with a JSON event
aws lambda invoke \
  --function-name resize-image \
  --payload '{"objectKey":"uploads/photo.jpg"}' \
  response.json

Run examples in a disposable training account and replace Regions, identifiers, policies, resource sizes, and names with reviewed values. Verify commands with the current AWS CLI and service documentation before production use.

Production guidance

  • Patch EC2 images and replace instances through an automated image pipeline.
  • Set Lambda memory, timeout, reserved concurrency, retries, and dead-letter behavior intentionally.
  • Measure startup latency and total cost instead of assuming one compute model is always cheaper.

The chapter quiz follows the lesson and checks both service vocabulary and architecture decisions.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement correctly describes Amazon EC2?
Which term matches this explanation: Resizable virtual server capacity with selectable instance families, images, networking, and storage.
Which statement correctly describes AMI?
Which term matches this explanation: A machine image template used to launch EC2 instances.
Which statement correctly describes Auto Scaling group?
Which term matches this explanation: A group that maintains and adjusts EC2 instance capacity according to policy.
Which statement correctly describes AWS Lambda?
Which term matches this explanation: Event-driven compute that runs function code without managing servers.
Which statement correctly describes instance profile?
Which term matches this explanation: An IAM role attachment that gives an EC2 workload temporary AWS credentials.

0 of 10 checks passed

Your progress is saved on this device.

Compute: EC2 and Lambda | AWS Lesson | Subha Prasad