SkillSprout
Chapter 6 · Lesson 3
Intermediate
5 min read

EC2, EBS, EFS and EKS for Developers

Overview

Not everything is serverless. Developers still deploy to Amazon EC2 virtual machines, attach EBS volumes or EFS file systems, and run containers on Amazon EKS (managed Kubernetes). The exam checks that you can bootstrap instances, give them credentials safely, pick the right storage and understand how EKS relates to ECS.

An EC2 instance is a rented computer. EBS is a hard drive plugged into one computer at a time, EFS is a shared network folder many computers mount at once, and EKS is a managed fleet controller that schedules your containers across many machines using Kubernetes.

The common theme is identity and configuration: use instance profiles instead of keys, user data to bootstrap, and IRSA / Pod Identity to give pods their own IAM roles.

Key Concepts

  • User data scripts run at first boot (cloud-init) to install and configure software; the instance metadata service v2 (IMDSv2) provides identity and tags using session tokens.
  • An instance profile attaches an IAM role to EC2 so applications receive rotating credentials from IMDS.
  • AMIs capture a bootable image; build golden images with EC2 Image Builder or Packer for faster, consistent launches.
  • EBS is block storage in a single AZ (gp3, io2, st1, sc1); snapshots are incremental backups stored in S3 and can copy across Regions.
  • EFS is a regional NFS file system shared across AZs and instances, and also mountable from Lambda and containers.
  • Instance store is ephemeral disk physically attached to the host and lost when the instance stops.
  • EKS runs the Kubernetes control plane for you; workers can be managed node groups, Fargate or self-managed nodes.
  • Pods get AWS permissions through IAM Roles for Service Accounts (IRSA) or EKS Pod Identity, not node roles.

Detailed Notes

Bootstrapping with user data and IMDSv2

bash
#!/bin/bash
dnf install -y nginx amazon-cloudwatch-agent
TOKEN=$(curl -s -X PUT http://169.254.169.254/latest/api/token \
  -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
ID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" \
  http://169.254.169.254/latest/meta-data/instance-id)
echo "Hello from $ID" > /usr/share/nginx/html/index.html
systemctl enable --now nginx

User data runs once as root by default and is limited to 16 KB. Require IMDSv2 (session-oriented requests) to mitigate SSRF theft of credentials. Applications using the SDK on EC2 pick up the instance profile automatically from IMDS.

EBS versus EFS versus instance store

AspectEBSEFSInstance store
TypeBlockNFS fileBlock (local)
ScopeOne AZ, usually one instanceRegional, many instancesOne host
PersistenceSurvives stopPersistentLost on stop/terminate
Typical useBoot disks, databasesShared content, CMS, ML dataCaches, scratch
ScaleProvisioned sizeElasticFixed by instance

For EBS pick gp3 (baseline 3,000 IOPS, independently tunable) for most workloads and io2 for latency-sensitive databases. Encrypt volumes with KMS; encryption covers snapshots and volumes created from them. Take snapshots before risky changes and automate with Data Lifecycle Manager.

bash
aws ec2 create-snapshot --volume-id vol-0abc123 --description "pre-release"
aws ec2 create-volume --snapshot-id snap-0def456 --availability-zone eu-west-1b --volume-type gp3

EFS offers General Purpose and Elastic throughput modes, lifecycle policies to move cold files to IA storage, and access points that enforce a user and root directory per application. Mount with the EFS helper using TLS.

bash
sudo mount -t efs -o tls fs-0123456789abcdef0:/ /mnt/shared

Auto Scaling and deployments

Pair EC2 with an Auto Scaling group and ALB; launch templates define AMI, instance profile and user data. CodeDeploy deploys to instances through an agent and appspec.yml. For immutable releases bake a new AMI and replace instances.

Amazon EKS for developers

EKS is certified Kubernetes. Applications are described with manifests applied by kubectl or Helm. Compare with ECS:

TopicECSEKS
OrchestratorAWS-nativeKubernetes
PortabilityAWS onlyMulti-cloud / on-premises tooling
Task/pod identityTask roleIRSA or Pod Identity
Learning curveLowerHigher
ComputeEC2 or FargateManaged nodes, Fargate, self-managed
bash
aws eks update-kubeconfig --name prod-cluster --region eu-west-1
kubectl apply -f deployment.yaml
kubectl rollout status deployment/orders
kubectl logs deployment/orders --tail=50

Create a service account annotated with a role ARN so a pod can call DynamoDB with only that role's permissions. Images come from ECR; use readiness and liveness probes so the service routes only to healthy pods, and Horizontal Pod Autoscaler for scaling.

Choosing compute

Use Lambda for event-driven short tasks, Fargate on ECS or EKS for containers without servers, EC2 when you need OS control, GPUs, custom kernels or long-running licensed software.

Real World Example

A CMS team ran four web servers, each with its own copy of uploaded images, so users saw missing files depending on which server answered. They moved uploads to EFS mounted by all instances (later S3 plus CloudFront), enforced IMDSv2, replaced hard-coded keys with an instance profile, and baked a golden AMI so scale-out takes minutes instead of running a long user-data install.

Architecture Diagram

EC2 fleet with shared storage
Architecture
Region
ALB
Auto Scaling group
Instancesinstance profile
EBS gp3
EFSshared

Instances use an instance profile and mount shared EFS while EBS holds local disks.

  1. 1The ALB sends requests to healthy instances in the group.
  2. 2Each instance boots from an AMI and runs user data.
  3. 3The instance profile supplies temporary AWS credentials.
  4. 4Shared files live on EFS while each instance keeps a private EBS volume.

Best Practices

  • ✓Use instance profiles and IMDSv2; never place access keys on instances.
  • ✓Bake golden AMIs and keep user data short for fast, repeatable scale-out.
  • ✓Choose EBS gp3 by default and encrypt volumes and snapshots.
  • ✓Use EFS (or S3) for shared files instead of copying data between instances.
  • ✓On EKS use IRSA or Pod Identity per workload plus readiness and liveness probes.

Common Interview Questions

Exam Tips

DVA-C02 focus

  • Data shared by many instances across AZs points to EFS.
  • EBS volumes are bound to an Availability Zone; use snapshots to move them.
  • Per-pod permissions on EKS means IRSA (or Pod Identity), not the node role.
  • Instance store data is lost when the instance stops.

Finished this lesson?

0 of 46 lessons done · 0% of the course