AWS for DevOps Engineers
Build reliable, secure systems on AWS. EKS, ECR with scanning, IAM/IRSA, VPC design, ALB Ingress Controller, CloudWatch, and multi-account architectures.
Lesson objective
- What it teaches
- Architecture & How It Works · Core Components · WSL Hands-On Lab · Real-World Project · Troubleshooting · Deep Dive: Multi-Account & Cost Controls · Enterprise: GuardDuty, Config & Transit Gateway · Predict the Result: Where the CLI Finds Credentials
- Why it matters
- A required lesson for Cloud Engineer, FinOps / Cloud Optimization, DevOps / Platform Architect. Recommended for DevOps Engineer, DevSecOps Engineer. See the role paths
- What you demonstrate
-
- Simulated lab: Run the first command shown in the section “WSL Hands-On Lab”. Recorded as lab evidence.
- Predict 3 results this lesson prints. You mark each one yourself.
- Optional, real environment: 10 hands-on tasks on your own machine or an external lab site (checklist). Not tracked as evidence.
Architecture & How It Works 11.1
AWS is organized into Regions containing multiple Availability Zones. EKS provides a managed control plane. IAM with IRSA allows pods to assume IAM roles via OIDC without long-lived credentials.
Core Components 11.2
| Service | DevOps Role | Key Integration |
|---|---|---|
| EKS | Managed Kubernetes | eksctl, EKS add-ons, ALB Ingress |
| ECR | Private registry | Scan on push, lifecycle policies |
| IAM / IRSA | Workload identity | OIDC provider, service account annotation |
| VPC CNI | Networking | ENI allocation, security groups |
| CloudWatch | Observability | Container Insights, Log Groups |
WSL Hands-On Lab 11.3
CLI → eksctl EKS → IRSA → Helm + ALB → ECR → CloudWatch
$ aws configure $ eksctl create cluster --name devops-lab --region us-east-1 --nodegroup-name ng --node-type t3.medium --nodes 2 $ eksctl create iamserviceaccount --name s3-reader --cluster devops-lab --attach-policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess --approve
- Configure AWS CLI and create EKS cluster with eksctl
- Deploy application using Helm with ALB Ingress
- Configure and test IRSA for S3 access from a pod
- Push image to ECR and configure lifecycle + scanning
- Enable Container Insights and validate metrics in CloudWatch
Least-Privilege IAM Policy: Condition Keys, Boundary Scoping, and Authorization Diagnosis
Upstream references: AWS S3 Actions & Condition Keys, AWS IAM Policy Evaluation Logic, and AWS STS DecodeAuthorizationMessage API.
Workload Assumptions: An EKS microservice running under Kubernetes service account payments-worker-sa in namespace payments assumes the IAM role arn:aws:iam::123456789012:role/payments-worker-role via IRSA. The service requires writing daily audit reports to S3 bucket acme-payments-ledger-prod-us-east-1 under prefix daily/ with mandatory AWS KMS encryption using key arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowListDailyPrefixOnly",
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": "arn:aws:s3:::acme-payments-ledger-prod-us-east-1",
"Condition": {
"StringLike": {
"s3:prefix": ["daily/*", "daily"]
}
}
},
{
"Sid": "AllowReadWriteDailyObjectsOnly",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::acme-payments-ledger-prod-us-east-1/daily/*",
"Condition": {
"Bool": {
"aws:SecureTransport": "true"
}
}
},
{
"Sid": "AllowKmsKeyUsageForS3",
"Effect": "Allow",
"Action": ["kms:GenerateDataKey", "kms:Decrypt"],
"Resource": "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012",
"Condition": {
"StringEquals": {
"kms:ViaService": "s3.us-east-1.amazonaws.com"
}
}
}
]
}
{
"DecodedMessage": {
"version": "1",
"context": {
"principal": {
"id": "AROAEXAMPLEID:payments-worker-session",
"arn": "arn:aws:sts::123456789012:assumed-role/payments-worker-role/payments-worker-session"
},
"action": "s3:PutObject",
"resource": "arn:aws:s3:::acme-payments-ledger-prod-us-east-1/daily/report-2026-10-14.parquet",
"conditions": {
"items": [
{
"key": "aws:SecureTransport",
"values": {
"items": [
{
"value": "false"
}
]
}
}
]
}
},
"result": {
"evaluationDecision": "ImplicitDeny",
"evalDecisionDetails": "no matching allow statement found for unencrypted transport"
}
}
}
| Request Context | Evaluated Condition | Decision | Root Cause & Remediation |
|---|---|---|---|
s3:PutObject unencrypted (HTTP) |
aws:SecureTransport == false |
ImplicitDeny |
Enforce TLS in client; policy requires aws:SecureTransport: "true". |
s3:PutObject to config/app.json |
Resource ARN path mismatch | ImplicitDeny |
Action not permitted outside daily/* scope. |
s3:PutObject with unauthorized KMS key |
KMS key ARN mismatch | AccessDenied |
Caller lacks kms:GenerateDataKey on requested key ARN. |
Real-World Project 11.4
EC2 + RDS + Route53 on free tier
EKS + ECR + RDS + ALB via eksctl and Terraform
Multi-account AWS Organizations + Control Tower + Transit Gateway + EKS Anywhere
Terraform EKS & VPC Architecture: Subnet Routing, Cost Analysis, and Teardown Precautions
Upstream references: AWS EKS VPC & Subnet Requirements Guide, HashiCorp AWS Provider EKS Cluster Documentation, and AWS EKS Pricing Model.
Topology Assumptions: Terraform >= 1.6.0, AWS Provider ~> 5.40. Dual-AZ VPC CIDR 10.0.0.0/16 in us-east-1 (AZs us-east-1a and us-east-1b). Offline HCL architecture without live terraform apply.
terraform {
required_version = ">= 1.6.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.40"
}
}
}
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
tags = { Name = "devops-eks-vpc" }
}
resource "aws_subnet" "public_1a" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
tags = {
Name = "public-us-east-1a"
"kubernetes.io/role/elb" = "1"
"kubernetes.io/cluster/devops-eks-cluster" = "shared"
}
}
resource "aws_subnet" "public_1b" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.2.0/24"
availability_zone = "us-east-1b"
map_public_ip_on_launch = true
tags = {
Name = "public-us-east-1b"
"kubernetes.io/role/elb" = "1"
"kubernetes.io/cluster/devops-eks-cluster" = "shared"
}
}
resource "aws_subnet" "private_1a" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.11.0/24"
availability_zone = "us-east-1a"
tags = {
Name = "private-us-east-1a"
"kubernetes.io/role/internal-elb" = "1"
"kubernetes.io/cluster/devops-eks-cluster" = "shared"
}
}
resource "aws_subnet" "private_1b" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.12.0/24"
availability_zone = "us-east-1b"
tags = {
Name = "private-us-east-1b"
"kubernetes.io/role/internal-elb" = "1"
"kubernetes.io/cluster/devops-eks-cluster" = "shared"
}
}
resource "aws_eks_cluster" "main" {
name = "devops-eks-cluster"
version = "1.30"
role_arn = "arn:aws:iam::123456789012:role/AmazonEKSClusterPolicy"
vpc_config {
endpoint_private_access = true
endpoint_public_access = false
subnet_ids = [aws_subnet.private_1a.id, aws_subnet.private_1b.id]
}
}
resource "aws_eks_node_group" "system_pool" {
cluster_name = aws_eks_cluster.main.name
node_group_name = "system-pool"
node_role_arn = "arn:aws:iam::123456789012:role/AmazonEKSWorkerNodePolicy"
subnet_ids = [aws_subnet.private_1a.id, aws_subnet.private_1b.id]
instance_types = ["t3.medium"]
scaling_config {
desired_size = 2
min_size = 2
max_size = 4
}
}
| EKS Infrastructure Component | Quantity / Sizing | Unit Rate (us-east-1) | Baseline Monthly Spend |
|---|---|---|---|
| EKS Managed Control Plane | 1 cluster | $0.10 / hour | $73.00 |
| AWS NAT Gateway | 1 gateway (public-1a) | $0.045 / hour | $32.85 |
| EC2 Worker Nodes (On-Demand) | 2 × t3.medium (2 vCPU, 4 GiB) | $0.0416 / instance-hour | $60.74 |
| EBS Root Volumes (gp3) | 2 × 20 GiB | $0.08 / GB-month | $3.20 |
| Baseline Total Spend | Standard multi-AZ cluster baseline | $169.79 / month | |
Teardown & Destroy Sequencing Precautions: When cloud controllers (e.g. AWS Load Balancer Controller or EBS CSI Driver) run inside the cluster, they dynamically create external ALBs, Target Groups, Security Groups, and ENIs that do not exist in Terraform state. Executing a naive terraform destroy causes AWS API failures with DependencyViolation because subnets cannot be deleted while active network interfaces remain attached.
#!/usr/bin/env bash
# Ordered teardown sequence preventing VPC subnet DependencyViolation
set -euo pipefail
echo "==> Step 1: Drain in-cluster cloud resources created by controllers"
kubectl delete ingress --all --all-namespaces
kubectl delete svc --field-selector spec.type=LoadBalancer --all-namespaces
kubectl delete pvc --all --all-namespaces
echo "==> Step 2: Verify all dangling ENIs in VPC have detached"
VPC_ID=$(terraform output -raw vpc_id 2>/dev/null || echo "vpc-12345678")
aws ec2 describe-network-interfaces \
--filters "Name=vpc-id,Values=${VPC_ID}" \
--query 'NetworkInterfaces[*].[NetworkInterfaceId,InterfaceType,Description]' \
--output table
echo "==> Step 3: Run planned Terraform destroy with protected databases"
# Stateful resources must declare lifecycle { prevent_destroy = true }
terraform destroy -auto-approve
Troubleshooting 11.5
EKS nodes not joining cluster
Check node IAM role, security groups, bootstrap logs, and subnet tags for the cluster.
Pod cannot access S3 via IRSA
Verify serviceaccount annotation, OIDC identity provider exists, and VPC endpoints if private.
ALB Ingress not creating load balancer
Confirm ingress class, subnet tags (kubernetes.io/role/elb), and IAM permissions for the ALB controller.
Simulated Incident: EKS Pod IRSA Authentication & Subnet Routing Failure
Upstream references: AWS EKS IRSA Troubleshooting Guide, AWS VPC Route Tables Guide, and AWS STS AssumeRoleWithWebIdentity API.
Incident Signature: Pods for order-processor deployed in namespace production fail startup with status CrashLoopBackOff. Application logs report AccessDenied: sts:AssumeRoleWithWebIdentity failed followed by ConnectTimeoutError: Connection to sqs.us-east-1.amazonaws.com timed out.
#!/usr/bin/env bash
# SIMULATED diagnostic sequence: trace pod identity projection and subnet routing
set -euo pipefail
echo "==> Step 1: Check pod token mount and projected service account"
kubectl -n production get pod -l app=order-processor \
-o jsonpath='{.items[0].spec.serviceAccountName}{"\n"}'
echo "==> Step 2: Audit IAM role trust relationship"
aws iam get-role --role-name order-processor-role \
--query 'Role.AssumeRolePolicyDocument' --output json
# DIAGNOSIS 1: The OIDC trust policy specifies:
# "oidc.eks.us-east-1.amazonaws.com/id/EXAMPLE:sub": "system:serviceaccount:staging:order-processor-sa"
# But the pod is running in namespace 'production' as 'system:serviceaccount:production:order-processor-sa'!
echo "==> Step 3: Trace private subnet route table for outbound egress"
SUBNET_ID=$(aws ec2 describe-instances --filters "Name=tag:aws:eks:cluster-name,Values=devops-eks-cluster" \
--query 'Reservations[0].Instances[0].SubnetId' --output text)
aws ec2 describe-route-tables --filters "Name=association.subnet-id,Values=${SUBNET_ID}" \
--query 'RouteTables[0].Routes' --output table
# DIAGNOSIS 2: Route 0.0.0.0/0 targets a deleted NAT Gateway id (nat-01122334455667788),
# creating a route blackhole for traffic destined to AWS public API endpoints!
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.us-east-1.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub": "system:serviceaccount:production:order-processor-sa",
"oidc.eks.us-east-1.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:aud": "sts.amazonaws.com"
}
}
}
]
}
#!/usr/bin/env bash
# SIMULATED remediation with safe rollback points
set -euo pipefail
RTB_ID="rtb-0123456789abcdef0"
ACTIVE_NAT="nat-09988776655443322"
echo "==> 1. Export pre-change route table state for safe rollback"
aws ec2 describe-route-tables --route-table-ids "${RTB_ID}" > rtb-backup.json
echo "==> 2. Remediate IAM trust policy for production namespace"
aws iam update-assume-role-policy \
--role-name order-processor-role \
--policy-document file://remediated-trust-policy.json
echo "==> 3. Replace blackhole default route with active NAT gateway"
aws ec2 replace-route \
--route-table-id "${RTB_ID}" \
--destination-cidr-block 0.0.0.0/0 \
--nat-gateway-id "${ACTIVE_NAT}"
echo "==> 4. Trigger rolling restart and verify pod recovery"
kubectl -n production rollout restart deployment/order-processor
kubectl -n production rollout status deployment/order-processor --timeout=60s
# If rollout fails, rollback trust policy and route:
# aws iam update-assume-role-policy --role-name order-processor-role --policy-document file://previous-trust-policy.json
# aws ec2 replace-route --route-table-id "${RTB_ID}" --destination-cidr-block 0.0.0.0/0 ...
30-Day Roadmap 11.6
- CLI + IAM mastery
- VPC deep dive
- EC2 + security groups
- eksctl clusters
- ALB Ingress Controller
- VPC CNI tuning
- IRSA + OIDC
- Least privilege roles
- Secrets Manager
- Organizations + SCPs
- Control Tower
- Transit Gateway
Deep Dive: Multi-Account & Cost Controls 11.7
Landing Zone Design
Use AWS Control Tower or custom terraform-aws-modules/organization. Create separate accounts for prod, non-prod, security, and network. Enforce SCPs and centralized logging.
Cost Observability
Enable Cost Explorer + CUR. Tag every resource with owner, environment, project. Use Kubecost or CloudWatch + Lambda to surface per-namespace spend on EKS.
Real Incident: Public S3 Bucket Exposes Customer PII
Discovery: GuardDuty at 02:30 UTC — S3/BucketPubliclyAccessible. Bucket made public by data engineer, containing 140K customer records.
# Auto-remediation Lambda triggered by GuardDuty EventBridge rule $ aws s3api put-public-access-block \ --bucket acme-analytics-exports-2024 \ --public-access-block-configuration \ BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true Bucket locked within 47 seconds of GuardDuty finding
Prevention: SCP denying s3:PutBucketAcl with public-read. AWS Config Rule auto-remediation. OPA in Terraform CI blocking public ACLs.
Enterprise: GuardDuty, Config & Transit Gateway 11.8
import boto3
def handler(event, context):
finding = event['detail']
finding_type = finding['type']
if 'S3/BucketPubliclyAccessible' in finding_type:
bucket = finding['resource']['s3BucketDetails'][0]['name']
boto3.client('s3').put_public_access_block(
Bucket=bucket,
PublicAccessBlockConfiguration={
'BlockPublicAcls': True, 'IgnorePublicAcls': True,
'BlockPublicPolicy': True, 'RestrictPublicBuckets': True
}
)
elif 'CryptoCurrency/BitcoinTool' in finding_type:
instance_id = finding['resource']['instanceDetails']['instanceId']
ec2 = boto3.client('ec2')
# Quarantine: apply deny-all security group
ec2.modify_instance_attribute(
InstanceId=instance_id,
Groups=['sg-quarantine-00000000']
)
# Snapshot for forensics
ec2.create_snapshots(
InstanceSpecification={'InstanceId': instance_id},
Description='GuardDuty forensic - cryptominer isolated'
)# Enable Security Hub + aggregate all org accounts $ aws securityhub enable-security-hub \ --enable-default-standards --region us-east-1 $ aws securityhub create-finding-aggregator \ --region-linking-mode ALL_REGIONS # List non-compliant S3 buckets $ aws configservice get-compliance-details-by-config-rule \ --config-rule-name s3-bucket-public-read-prohibited \ --compliance-types NON_COMPLIANT
resource "aws_ec2_transit_gateway" "main" {
description = "Enterprise hub TGW"
auto_accept_shared_attachments = "disable"
default_route_table_association = "disable"
tags = { Name = "enterprise-tgw" }
}
# Share TGW with spoke accounts via RAM
resource "aws_ram_resource_share" "tgw" {
name = "transit-gateway-share"
}
resource "aws_ram_resource_association" "tgw" {
resource_arn = aws_ec2_transit_gateway.main.arn
resource_share_arn = aws_ram_resource_share.tgw.arn
}
# Spoke account attaches their VPC
resource "aws_ec2_transit_gateway_vpc_attachment" "spoke" {
transit_gateway_id = data.aws_ec2_transit_gateway.hub.id
vpc_id = aws_vpc.spoke.id
subnet_ids = aws_subnet.private[*].id
}module "eks_blueprints_addons" {
source = "aws-ia/eks-blueprints-addons/aws"
version = "~> 1.0"
cluster_name = module.eks.cluster_name
cluster_endpoint = module.eks.cluster_endpoint
cluster_version = module.eks.cluster_version
oidc_provider_arn = module.eks.oidc_provider_arn
eks_addons = {
vpc-cni = {
most_recent = true
configuration_values = jsonencode({
env = {
ENABLE_PREFIX_DELEGATION = "true" # 110 pods/node vs 29
}
})
}
aws-ebs-csi-driver = { most_recent = true }
coredns = { most_recent = true }
kube-proxy = { most_recent = true }
}
enable_aws_load_balancer_controller = true
enable_karpenter = true
enable_cert_manager = true
enable_external_secrets = true
enable_aws_for_fluentbit = true
}- Enable GuardDuty, create EventBridge + Lambda auto-remediation for public S3 findings
- Enable AWS Config + Security Hub, verify s3-bucket-public-read-prohibited compliance
- Deploy EKS Blueprints addons: ALB controller + Karpenter + prefix delegation VPC CNI
- Write SCP denying s3:PutBucketAcl with public-read across all non-sandbox accounts
- Design Transit Gateway hub-spoke architecture for prod + dev + shared-services accounts
Predict the Result: Where the CLI Finds Credentials 11.9
Recorded from a real run of scripts/recordings/aws.sh; every output below is pasted from scripts/recordings/aws.out. Cover the output, predict it, then compare.
Environment: amazon/aws-cli:2.22.35 container with no ~/.aws directory, AWS_REGION=us-east-1 and instance metadata disabled (AWS_EC2_METADATA_DISABLED=true), so nothing in the credential chain exists. The last command uses the documentation example keys and reaches the real STS endpoint.
# No credentials anywhere in the chain $ aws sts get-caller-identity; echo "exit=$?" Unable to locate credentials. You can configure credentials by running "aws configure". exit=253 # Where each setting would come from $ aws configure list Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key <not set> None None secret_key <not set> None None region us-east-1 env ['AWS_REGION', 'AWS_DEFAULT_REGION'] # Well-formed keys that AWS does not recognise $ AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY aws sts get-caller-identity; echo "exit=$?" An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid. exit=254
The CLI looks for credentials in order: environment variables, the shared credentials and config files (including SSO and assume-role profiles), then container or instance metadata. aws configure list shows which source won. Exit 253 means no credentials were found; 254 means AWS rejected the request. aws sts get-caller-identity is the quickest check of who you are before running anything destructive.