devHọc Dev

Week 1 - Day 2: VPC, EC2/Auto Scaling, and S3 Fundamentals Review

Week 1 – Day 2

This lesson combines 3 topics: VPC Fundamentals Review, EC2 and Auto Scaling Review, S3 and Storage Review.

Learning Objectives

  • Review the core VPC concepts
  • Understand Subnets, Route Tables, and Gateways clearly
  • Master Security Groups and NACLs
  • Review EC2 instance types and pricing models
  • Understand Auto Scaling Groups in depth
  • Master the scaling strategies
  • Review S3 storage classes and lifecycle policies
  • Understand S3 security and encryption
  • Master S3 performance optimization

Part 1: VPC Fundamentals Review

1. VPC Overview

Definition

A VPC (Virtual Private Cloud) is an isolated virtual network in the AWS cloud where you have full control over:

  • IP address range (CIDR block)
  • Subnets
  • Route tables
  • Network gateways
  • Security settings

VPC CIDR Block

Allowed range: /16 (65,536 IPs) to /28 (16 IPs)

Examples:
10.0.0.0/16    →  10.0.0.0 - 10.0.255.255 (65,536 IPs)
172.16.0.0/16  →  172.16.0.0 - 172.16.255.255
192.168.0.0/16 →  192.168.0.0 - 192.168.255.255

Reserved IPs in each Subnet

Subnet: 10.0.1.0/24 (256 IPs total, 251 usable)

10.0.1.0   - Network address
10.0.1.1   - VPC Router
10.0.1.2   - DNS Server
10.0.1.3   - Reserved for future use
10.0.1.255 - Broadcast address (not used in a VPC)

2. Subnet Architecture

Public vs Private Subnet

┌─────────────────────────────────────────────────────────┐│VPC││┌─────────────────────┐┌─────────────────────────┐│││PublicSubnet││PrivateSubnet││││││││││┌─────────────┐││┌─────────────────┐│││││WebServer││││Database││││││(PublicIP)││││(PrivateIP)│││││└─────────────┘││└─────────────────┘││││││││││││▼││▼││││Route:0.0.0.0/0││Route:0.0.0.0/0││││→InternetGW││→NATGateway│││└─────────────────────┘└─────────────────────────┘││││││▼▼││┌──────────────┐┌──────────────┐│││InternetGW││NATGateway│││└──────────────┘└──────────────┘│└─────────────────────────────────────────────────────────┘

Conditions for a Subnet to be Public

  1. It has a route to an Internet Gateway
  2. Instances have a Public IP or Elastic IP

3. Route Tables

Route Table structure

Destination     Target          Status    Propagated
-----------     ------          ------    ----------
10.0.0.0/16     local           Active    No
0.0.0.0/0       igw-xxxxx       Active    No

Route Priority

  • Most specific route wins (longest prefix match)
  • 10.0.1.0/24 takes priority over 10.0.0.0/16

Target types

TargetDescription
localTraffic within the VPC
igw-xxxInternet Gateway
nat-xxxNAT Gateway
vgw-xxxVirtual Private Gateway
tgw-xxxTransit Gateway
pcx-xxxVPC Peering Connection
vpce-xxxVPC Endpoint

4. Internet Gateway (IGW)

Characteristics

  • Horizontally scaled, redundant, highly available
  • A VPC can attach only 1 IGW
  • Performs NAT for instances with a public IP

Steps for internet access

  1. Attach the IGW to the VPC
  2. Add a route 0.0.0.0/0 → IGW in the route table
  3. Associate the route table with the subnet
  4. Instances need a public IP

5. NAT Gateway vs NAT Instance

Comparison

FeatureNAT GatewayNAT Instance
AvailabilityHighly available within an AZSelf-managed
BandwidthUp to 100 GbpsDepends on instance type
MaintenanceManaged by AWSSelf-managed
Security GroupsNot supportedSupported
Bastion hostNoPossible
CostHourly + dataInstance cost

NAT Gateway Best Practice

┌─────────────────────────────────────────────┐│VPC││┌──────────────┐┌──────────────┐│││AZ-1a││AZ-1b││││┌──────────┐││┌──────────┐│││││NATGW1││││NATGW2│││││└──────────┘││└──────────┘││││↑││↑││││┌──────────┐││┌──────────┐│││││Private││││Private││││││Subnet││││Subnet│││││└──────────┘││└──────────┘│││└──────────────┘└──────────────┘│└─────────────────────────────────────────────┘→EachAZhasitsownNATGatewayforhigheravailability

6. Security Groups vs NACLs

Detailed comparison

FeatureSecurity GroupNACL
LevelInstance (ENI)Subnet
StateStatefulStateless
RulesAllow onlyAllow & Deny
EvaluationAll rulesRules by number
DefaultDeny all inboundAllow all

Stateful vs Stateless

Security Group (Stateful):
Request:  Inbound port 80 ALLOWED → Response auto allowed
Response: Outbound auto allowed

NACL (Stateless):
Request:  Inbound port 80 ALLOWED
Response: Outbound ephemeral ports MUST be explicitly allowed

Ephemeral Ports

Linux: 32768-65535
Windows: 49152-65535
NAT Gateway: 1024-65535

7. VPC Flow Logs

Capture levels

  1. VPC level: All ENIs in the VPC
  2. Subnet level: All ENIs in the subnet
  3. ENI level: Specific ENI

Destinations

  • CloudWatch Logs
  • S3 bucket
  • Amazon Data Firehose (formerly Kinesis Data Firehose)

Flow Log Record Format

<version> <account-id> <interface-id> <srcaddr> <dstaddr>
<srcport> <dstport> <protocol> <packets> <bytes>
<start> <end> <action> <log-status>

Part 2: EC2 and Auto Scaling Review

1. EC2 Instance Types

Naming Convention

m5.xlarge│││││└──Size:nano,micro,small,medium,large,xlarge,2xlarge...│└──────Generation:highernumber=newer└────────Family:m(general),c(compute),r(memory),etc.

Instance Families

FamilyOptimized forUse Cases
M (General)BalancedWeb servers, app servers
C (Compute)CPUBatch processing, gaming
R (Memory)RAMIn-memory databases, caching
X (Memory)Extreme RAMSAP HANA, large databases
I (Storage)High I/ONoSQL, data warehousing
D (Dense)HDD storageDistributed file systems
G/P (Accelerated)GPUML, graphics rendering
T (Burstable)Burst CPUVariable workloads

T Instances and CPU Credits

T3InstanceCPUCreditSystem:CPUUsage100%├────────────────┐│Burst│←Spendcredits20%├────────────────┼──────────────│Baseline│←Earncredits0%└────────────────┴──────────────→TimeWhencreditsrunout:-T3Standard:Throttledtobaseline-T3Unlimited:Keepsbursting,paysextra

2. EC2 Pricing Models

Comparing the pricing models

ModelDiscountCommitmentBest For
On-Demand0%NoneShort-term, unpredictable
Reserved1yr up to ~40%, 3yr up to ~72%1 or 3 yearsSteady-state workloads
Savings PlansCompute up to 66%, EC2 Instance up to 72%1 or 3 yearsFlexible compute usage
Spotup to 90%NoneFault-tolerant, flexible
Dedicated HostVariesPer hostLicensing, compliance

Discount figures used consistently across this course: Standard RI 3yr up to 72%, Convertible RI 3yr up to 66%, Compute Savings Plans up to 66%, EC2 Instance Savings Plans up to 72%, Spot up to 90%. Purchase options and Spot allocation are covered in detail in Week 3 Day 1 (Part 1).

Reserved Instances Types

Standard RI:
- Highest discount (up to 72%)
- Can be sold on the Marketplace
- Cannot change instance family

Convertible RI:
- Lower discount (up to 66% for 3-year term)
- Can change instance family, OS, tenancy
- Cannot be sold on the Marketplace

Savings Plans

Compute Savings Plans:
- Applies to EC2, Lambda, Fargate
- Flexible across regions, instance families
- Up to 66% discount

EC2 Instance Savings Plans:
- Specific to instance family in a Region
- Up to 72% discount
- Less flexible

Spot Instances

Spot Request Types:

1. One-time Request
   - Launched → Running → Terminated when interrupted

2. Persistent Request
   - Automatically re-requests if interrupted
   - Stays valid until canceled

Spot Fleet:
- Collection of Spot + On-Demand instances
- Automatically maintains target capacity
- Diversified allocation strategy

3. EC2 Placement Groups

The three Placement Group types

1.CLUSTER(LowLatency)┌─────────────────────────┐│SameRack,SameAZ││┌───┐┌───┐┌───┐│││EC2││EC2││EC2│││└───┘└───┘└───┘│└─────────────────────────┘Use:HPC,Low-latencyapps2.SPREAD(HighAvailability)┌─────┐┌─────┐┌─────┐│Rack1││Rack2││Rack3││┌───┐││┌───┐││┌───┐│││EC2││││EC2││││EC2│││└───┘││└───┘││└───┘│└─────┘└─────┘└─────┘Max:7instancesperAZUse:Criticalapps3.PARTITION(LargeDistributed)┌──────────┬──────────┬──────────┐│Partition1│Partition2│Partition3││┌───┐│┌───┐│┌───┐│││EC2│││EC2│││EC2││││EC2│││EC2│││EC2│││└───┘│└───┘│└───┘│└──────────┴──────────┴──────────┘Use:HDFS,Cassandra,Kafka

4. Auto Scaling Groups (ASG)

Components

┌─────────────────────────────────────────────────┐│AutoScalingGroup││││┌─────────────────┐┌─────────────────────┐│││LaunchTemplate││ScalingPolicies││││-AMI││-TargetTracking││││-InstanceType││-StepScaling││││-SecurityGrp││-SimpleScaling││││-UserData││-Scheduled│││└─────────────────┘└─────────────────────┘││││CapacitySettings:││-Minimum:2││-Desired:4││-Maximum:10│└─────────────────────────────────────────────────┘

Launch Template vs Launch Configuration

FeatureLaunch TemplateLaunch Config
VersioningYesNo
Multiple instance typesYesNo
Spot + On-Demand mixYesNo
T2/T3 UnlimitedYesNo
RecommendedYesLegacy

5. Scaling Policies

Policy: Keep Average CPU at 50%

CPU = 70% → Scale OUT (add instances)
CPU = 30% → Scale IN (remove instances)
CPU = 50% → No action

Step Scaling

CPU Usage    Action
0-40%        Remove 2 instances
40-60%       No change
60-80%       Add 1 instance
80-100%      Add 3 instances

Scheduled Scaling

{
  "ScheduledActionName": "scale-out-morning",
  "Recurrence": "0 9 * * MON-FRI",
  "MinSize": 5,
  "MaxSize": 20,
  "DesiredCapacity": 10
}

Predictive Scaling

  • Uses ML to forecast traffic patterns
  • Proactive scaling before load increases
  • Combined with dynamic scaling

6. Scaling Cooldowns

ScaleOutEvent│▼┌────────────┐Cooldown┌────────────┐│Add2Inst│────(300sec)─────►│Readyfor│└────────────┘│nextscale│└────────────┘Purpose:-Avoidscalingtoofast-Waitformetricstostabilize-Default:300seconds

7. Health Checks

Types

TypeDefaultChecks
EC2YesInstance status
ELBOptionalHTTP health check
CustomOptionalExternal health system

Grace Period

  • Wait time after an instance launches
  • New instances are not terminated during the grace period
  • Default: 300 seconds

8. Cross-Zone Load Balancing

The problem: instances unevenly distributed across AZs

WITHOUTCross-ZoneLoadBalancing:┌──────────────┐│LoadBalancer││50%50%│←eachAZ'sLBnodegets50%oftraffic└───┬──────┬───┘┌─────────┘└──────────┐┌────▼─────┐┌──────▼───────────────┐│AZ-1││AZ-2││┌──────┐││┌───┐┌───┐...┌───┐│││EC2││││EC2││EC2││EC2│││└──────┘││└───┘└───┘└───┘││1inst││9instances││=50%!││=50%/9≈5.6%/inst│└──────────┘└──────────────────────┘WITHCross-ZoneLoadBalancing:→Eachinstancegets100%/10=10%,regardlessofAZ

When instance counts are uneven across AZs (for example 1 vs 9) and cross-zone is not enabled, each LB node only distributes to targets in its own AZ → the lone instance in AZ-1 carries 50% of all traffic and gets overloaded. Enable cross-zone → every LB node distributes evenly to all targets in every AZ.

Comparison by Load Balancer type

ALBNLBGWLB
DefaultAlways ON at LB levelOFFOFF
Can it be toggled?Can be turned off per target groupTurn on at LB levelTurn on at LB level
Inter-AZ data transfer chargeFreeCharged when enabledCharged when enabled

Professional-level notes:

  • ALB: cross-zone is on by default and inter-AZ data transfer is free. There is almost no reason to turn it off, except when you need zonal isolation (combined with zonal DNS affinity).
  • NLB: off by default to avoid inter-AZ charges and preserve zonal isolation; only turn it on when you accept the charge to balance traffic.
  • With an ASG: configure the ASG to spread instances evenly across AZs (balanced AZs) so you do not depend on cross-zone.

Exam keyword: "uneven traffic distribution across AZs" / one AZ with few instances receives the same traffic as an AZ with many instances → enable Cross-Zone Load Balancing (remember: NLB is off by default + inter-AZ charges, ALB is on by default + free).

9. ASG Instance Refresh and EC2 Instance Recovery

ASG Instance Refresh

Rolling replacement of all instances in the ASG according to a new launch template. Use it when you patch the AMI, change the instance type, or fix user data, with no need to terminate each instance manually.

InstanceRefresh(MinHealthyPercentage=90%):ASG10instances(AMIv1)│▼replacebatchbybatch,alwayskeep≥9healthy┌─────────────────────────────────────┐│Terminate1(v1)→Launch1(v2)││→waitInstanceWarmup→nextbatch│└─────────────────────────────────────┘│▼ASG10instances(AMIv2)

Key parameters:

ParameterMeaning
MinHealthyPercentageMinimum % of capacity that must stay healthy during the refresh (e.g. 90% → replace at most 10% per round)
InstanceWarmupTime to wait for a new instance to "warm up" before it counts as healthy and the next batch is replaced
CheckpointsPause at % milestones (e.g. 25%, 50%) awaiting confirmation: a canary-style rollout
Skip matchingSkip instances already on the new launch template version → no unnecessary replacements
Auto rollbackAutomatically roll back to the old configuration if the refresh fails or a CloudWatch alarm triggers

Exam keyword: "update the AMI for all instances in an ASG with least operational overhead" → Instance Refresh (NOT manually terminating each instance or creating a new ASG).

EC2 Instance Recovery (CloudWatch alarm action)

Create a CloudWatch alarm on the StatusCheckFailed_System metric with the alarm action recover → when the underlying AWS hardware fails, the instance is automatically recovered onto a new physical host.

After recovery, the instance keeps:

  • Instance ID
  • Private IP (a private IP stays the same within a VPC for the life of the instance anyway)
  • Elastic IP
  • Instance metadata

(Equivalent to a stop/start that AWS performs automatically onto another host; within a VPC, the private IP does not change.)

Requirements: the instance is EBS-backed and does not use instance store volumes (instance store data would be lost, and some instance types do not support recover).

System vs Instance status check

System status checkInstance status check
MetricStatusCheckFailed_SystemStatusCheckFailed_Instance
Where the failure isAWS hardware/host (power, network of the physical host)OS level (kernel panic, memory exhausted, wrong network config in the OS)
Who handles itAWS, or you use the alarm action recoverYou: the recover action does NOT help; you need reboot or an OS fix

Exam keyword: "automatically recover instance when underlying hardware fails, keeping the same instance ID/IP" → CloudWatch alarm StatusCheckFailed_System + action recover.

Part 3: S3 and Storage Review

1. S3 Storage Classes

Comparing Storage Classes

ClassAvailabilityDurabilityMin DurationUse Case
Standard99.99%99.999999999%NoneFrequently accessed
Express One Zone99.95%99.999999999%1 hourUltra-low latency (single-digit ms), AI/ML training, request-heavy
Intelligent-Tiering99.9%99.999999999%NoneUnknown pattern
Standard-IA99.9%99.999999999%30 daysInfrequent access
One Zone-IA99.5%99.999999999%30 daysNon-critical, infrequent
Glacier Instant99.9%99.999999999%90 daysArchive, instant access
Glacier Flexible99.99%99.999999999%90 daysArchive, minutes-hours
Glacier Deep Archive99.99%99.999999999%180 daysLong-term archive

S3 Express One Zone (GA Nov 2023)

A very high-performance storage class designed for workloads that need the lowest-latency access.

Key characteristics:

  • Latency: single-digit millisecond (10x faster than S3 Standard)
  • Throughput: millions of requests per second per bucket (single-digit ms first-byte latency)
  • Storage: in a single Availability Zone only (lower latency, but loses cross-AZ HA)
  • Pricing (after the 10/04/2025 price cut): storage ~$0.11/GB-month (us-east-1), about 4.8x S3 Standard ($0.023); requests are much cheaper than Standard. The 04/2025 cut reduced storage by another 31%, PUT by 55%, GET by 85%, and per-GB upload/retrieval charges by 60%. Trade-off: storage is much more expensive, requests are cheap → worth it for request-heavy workloads with small objects, not worth it for long-lived, rarely accessed data
  • Min storage duration: 1 hour (versus 30 days for Standard-IA)
  • Bucket type: Directory bucket (a different structure from regular buckets, used for high-performance patterns)

Use cases:

  • AI/ML training data with millions of small objects
  • High-frequency trading, real-time analytics
  • Interactive applications that read/write at high frequency
  • Workloads whose data can be regenerated (because single-AZ → losing the AZ = losing the data)

Trade-offs SAP-C02 often asks about:

  • Single-AZ → do NOT use for mission-critical data (no cross-AZ redundancy)
  • High storage cost → only use it when latency/throughput really matters
  • Does not support replication or full versioning like S3 Standard
  • Requires a Directory bucket, not a General-purpose bucket

S3 Intelligent-Tiering

┌────────────────────────────────────────────────┐│S3Intelligent-Tiering││││┌──────────────┐│││Frequent│←Objectsaccessed│││AccessTier│within30days││└──────┬───────┘│││Noaccess30days││▼││┌──────────────┐│││Infrequent│←Auto-moved│││AccessTier│(40%costsavings)││└──────┬───────┘│││Noaccess90days(opt-in)││▼││┌──────────────┐│││Archive│←Optionaltier│││AccessTier│(68%costsavings)││└──────┬───────┘│││Noaccess180days(opt-in)││▼││┌──────────────┐│││DeepArchive│←Optionaltier│││AccessTier│(95%costsavings)││└──────────────┘│└────────────────────────────────────────────────┘

Glacier Retrieval Options

TierGlacier FlexibleDeep ArchiveTime
Expedited$$N/A1-5 minutes
Standard$$3-5 hours / 12 hours
Bulk¢¢5-12 hours / 48 hours

2. S3 Lifecycle Policies

Example Policy

{
  "Rules": [
    {
      "ID": "Move to IA after 30 days",
      "Status": "Enabled",
      "Filter": {"Prefix": "logs/"},
      "Transitions": [
        {
          "Days": 30,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 90,
          "StorageClass": "GLACIER"
        }
      ],
      "Expiration": {
        "Days": 365
      }
    }
  ]
}

Lifecycle Flow

Day0Day30Day90Day365││││▼▼▼▼┌────────┐┌────────┐┌────────┐┌────────┐│Standard│────────►│IA│────────►│Glacier│─────────►│DELETE│└────────┘└────────┘└────────┘└────────┘

3. S3 Security

Access Control Methods

┌─────────────────────────────────────────────────┐│S3AccessControl│├─────────────────────────────────────────────────┤│1.BucketPolicies(Resource-based)││-JSONpolicyattachedtobucket││-Cross-accountaccess││││2.IAMPolicies(Identity-based)││-Attachedtousers,groups,roles││-Sameaccountonly││││3.ACLs(Legacy-notrecommended)││-BucketACL/ObjectACL││││4.AccessPoints││-Simplifiedaccessmanagement││-Eachwithitsownpolicy│└─────────────────────────────────────────────────┘

Block Public Access

Account Level + Bucket Level Settings:
- BlockPublicAcls
- IgnorePublicAcls
- BlockPublicPolicy
- RestrictPublicBuckets

Best Practice: Enable all blocks unless explicitly needed

4. S3 Encryption

Encryption Types

Server-SideEncryption(SSE):┌─────────────────────────────────────────────────┐│SSE-S3(Amazonmanagedkeys)││-AWSmanageskeysentirely││-Header:x-amz-server-side-encryption:AES256│├─────────────────────────────────────────────────┤│SSE-KMS(AWSKMSmanagedkeys)││-Morecontroloverkeys││-AudittrailinCloudTrail││-Header:x-amz-server-side-encryption:aws:kms│├─────────────────────────────────────────────────┤│SSE-C(Customer-providedkeys)││-Customermanageskeys││-MustuseHTTPS││-Providekeywitheachrequest│└─────────────────────────────────────────────────┘Client-SideEncryption:-Encryptbeforeupload-Customermanageskeysentirely

Encryption at rest - Best Practice

Bucket Default Encryption:
{
  "Rules": [{
    "ApplyServerSideEncryptionByDefault": {
      "SSEAlgorithm": "aws:kms",
      "KMSMasterKeyID": "arn:aws:kms:region:account:key/key-id"
    },
    "BucketKeyEnabled": true  ← Reduces KMS API calls
  }]
}

5. S3 Performance

Baseline Performance

  • 3,500 PUT/COPY/POST/DELETE requests per second per prefix
  • 5,500 GET/HEAD requests per second per prefix

Multi-Part Upload

File Size Recommendation:
< 100 MB    → Single PUT
≥ 100 MB    → Multi-Part Upload (recommended)
> 5 GB      → Multi-Part Upload (required)

Benefits:
- Parallel uploads
- Pause and resume
- Begin upload before knowing final size

S3 Transfer Acceleration

WithoutTransferAcceleration:User(Vietnam)──────longdistance────────►S3(us-east-1)WithTransferAcceleration:User(Vietnam)──►EdgeLocation──AWSbackbone──►S3(us-east-1)(Singapore)

S3 Byte-Range Fetches

LargeFile(10GB)┌────┬────┬────┬────┬────┐│1│2│3│4│5│←Parallelbyte-rangerequests└────┴────┴────┴────┴────┘Usecases:-Paralleldownloads-Resumefaileddownloads-Getspecificportions(headersonly)

6. S3 Replication

Types

FeatureSame-Region (SRR)Cross-Region (CRR)
Use CaseLog aggregationCompliance, DR
LatencyLowHigher
RegionsSameDifferent

Requirements

  • Versioning enabled on both buckets
  • IAM permissions for replication
  • Objects encrypted with SSE-S3, SSE-KMS, DSSE-KMS, or SSE-C can all be replicated (SSE-KMS/DSSE-KMS must be enabled in the replication rule, and the key policy must allow the replication role)

What's NOT replicated

  • Objects before replication enabled (use S3 Batch Replication to replicate existing objects)
  • Objects the bucket owner has no permission on (objects uploaded by another account without owner override)
  • Delete markers (optional to replicate)
  • Lifecycle rules actions

7. S3 Event Notifications

Destinations

S3Events───►Lambda├──►SNS├──►SQS└──►EventBridge(recommendedforcomplexrouting)

Event Types

  • s3:ObjectCreated:*
  • s3:ObjectRemoved:*
  • s3:ObjectRestore:*
  • s3:Replication:*

Review Questions

  1. How many Internet Gateways can a VPC have?

    Show answer

    1 IGW per VPC: a 1-to-1 relationship. An IGW is highly available (horizontally scaled, redundant), so it is not a SPOF. You cannot attach 2 IGWs to 1 VPC, and 1 IGW cannot be attached to 2 VPCs at once. To give multiple VPCs internet access, each VPC needs its own IGW, or you use a centralized egress VPC via Transit Gateway.

  2. What is the main difference between a Security Group and a NACL?

    Show answer

    Security Group: instance-level (ENI), stateful (responses auto-allowed), Allow rules only, evaluates all rules. NACL: subnet-level, stateless (needs explicit inbound + outbound rules), has both Allow and Deny rules, rules evaluated in numbered order. SGs give fine-grained instance control; NACLs give subnet-level blocking (for example: blocking a malicious IP with a Deny rule, which you cannot do with an SG).

  3. Why do you need a NAT Gateway in each AZ?

    Show answer

    A NAT Gateway is AZ-scoped: it only serves instances in that AZ. If there is only 1 NAT GW in AZ-a: (1) traffic from private instances in AZ-b must cross AZs to AZ-a → incurs cross-AZ data transfer cost ($0.01/GB), (2) if AZ-a fails → all private instances lose internet access. A NAT GW per AZ = HA + no cross-AZ cost overhead.

  4. Which subnet is called a public subnet?

    Show answer

    A subnet is called public when its route table has a route 0.0.0.0/0 → IGW. A subnet is not public or private by itself: the route table decides. In addition, instances in a public subnet need a Public IP or Elastic IP to receive inbound traffic from the internet. Best practice: turn off auto-assign public IP and only give Elastic IPs to instances that really need them.

  5. Which destinations can Flow Logs be sent to?

    Show answer

    3 destinations: (1) CloudWatch Logs: real-time monitoring, Insights queries, alarms, (2) S3 bucket: long-term storage, Athena queries, cheaper, (3) Amazon Data Firehose (formerly Kinesis Data Firehose): streaming to Redshift, OpenSearch, S3. Capture can be at the VPC level, Subnet level, or ENI level. Some traffic is not captured: DHCP, IMDS, Amazon DNS (169.254.169.253).

  6. What is the difference between Standard and Convertible Reserved Instances?

    Show answer

    Standard RI: higher discount (~72%), cannot change instance family/OS/tenancy during the term, can be sold on the RI Marketplace. Convertible RI: lower discount (up to 66%), can be exchanged for another RI of equal or greater value (change family, OS, tenancy, Region), cannot be sold. Choose Standard when the workload is clearly stable; Convertible when you need flexibility because the technology roadmap is uncertain.

  7. When should you use Spot Instances?

    Show answer

    Spot fits fault-tolerant, stateless workloads: batch processing, data analytics (Spark/Hadoop), ML training, CI/CD workers, image/video rendering, genomics. Key requirements: (1) the app can checkpoint and resume, (2) no guaranteed uptime is needed, (3) it can handle the 2-minute interruption warning. Do not use for: production databases, stateful web servers (with no fallback), real-time customer-facing APIs.

  8. What are the three Placement Group types and their use cases?

    Show answer

    (1) Cluster: same rack in 1 AZ, low-latency 10+ Gbps network, for HPC, ML training, big data (Hadoop). (2) Spread: each instance on separate hardware, cross-AZ, max 7 instances/AZ, for critical apps needing maximum HA (avoiding correlated hardware failures). (3) Partition: groups of instances, each partition separated by hardware, for distributed databases (Cassandra, HDFS, HBase) that need topology-aware replication.

  9. Why should you use a Launch Template instead of a Launch Configuration?

    Show answer

    Launch Templates support: versioning (roll back to an old version), multiple instance types (Mixed Instances Policy), Spot + On-Demand in the same ASG, T2/T3 unlimited, and all new EC2 features. Launch Configuration is legacy (deprecated 2022): no versioning, only 1 instance type, incompatible with many new features. AWS no longer lets you create new Launch Configurations.

  10. How does a Target Tracking Scaling policy work?

Show answer

Target Tracking maintains a metric at the target value you set: the ASG automatically scales out/in to keep the metric close to the target. Example: target CPU = 50% → when CPU > 50%, the ASG adds instances; when CPU < 50%, the ASG removes instances (after cooldown). It is the simplest of the 4 scaling policies: no need to define complex thresholds. AWS recommends using CPU, ALB Request Count per Target, or a custom metric from CloudWatch.

  1. An NLB spans 2 AZs: AZ-1 runs 1 instance, AZ-2 runs 9 instances. The instance in AZ-1 is constantly overloaded. What is the cause and how do you fix it?
Show answer

An NLB has Cross-Zone Load Balancing OFF by default → each LB node only distributes to targets in its own AZ: AZ-1 receives 50% of traffic, all of it going to 1 instance. Fix: (1) enable cross-zone at the NLB level, so each instance gets an even 10%, but inter-AZ data transfer charges apply, or (2) rebalance the instance count across AZs (ASG with balanced AZs). Note: an ALB does not have this problem because cross-zone is always on and inter-AZ traffic is free.

  1. You need to roll out a new (patched) AMI to all 50 instances in an ASG with least operational overhead and no downtime. What is the solution?
Show answer

Create a new launch template version with the patched AMI, then run ASG Instance Refresh: an automatic rolling replacement of all instances. Set MinHealthyPercentage (e.g. 90%) to keep capacity during the refresh, InstanceWarmup so new instances stabilize before the next batch is replaced, and enable auto rollback with a CloudWatch alarm to revert to the old version automatically if the deployment fails. You can use checkpoints for a canary-style rollout. This is the correct answer rather than manually terminating each instance or creating a new ASG/blue-green setup (more operational overhead).

  1. An object must be stored for 30 days and then moved to Glacier. Which class should you choose?
Show answer

Standard for the first 30 days (no minimum duration), then transition to Glacier Instant Retrieval or Glacier Flexible Retrieval (minimum 90 days). If you know this pattern in advance, configure an S3 Lifecycle rule: STANDARD → GLACIER after 30 days. Note: Standard-IA has a 30-day minimum, so it saves nothing if objects live < 30 days.

  1. What is the difference between SSE-S3 and SSE-KMS?
Show answer

SSE-S3: AWS manages the keys entirely, no separate audit trail, free, you cannot control key rotation. SSE-KMS: uses a KMS customer managed key, every operation creates a CloudTrail entry (audit trail), you can set a key rotation policy, you can revoke the key (blocking access immediately), and KMS API calls are charged. Compliance environments need SSE-KMS for a data access audit trail.

  1. When should you use S3 Transfer Acceleration?
Show answer

When uploading from geographically far from the bucket's Region, for example uploading from Vietnam to us-east-1. Transfer Acceleration routes through the nearest Edge Location → AWS backbone network → bucket, instead of going entirely over the public internet. Most effective for: uploads > 1 GB over distances > 1,000 km, global mobile apps, content ingestion from multiple continents. Test the speed at: s3-accelerate-speedtest.s3-accelerate.amazonaws.com.

  1. Does S3 Replication replicate delete markers?
Show answer

It depends on the configuration. By default, replication rules do not replicate delete markers (S3 deliberately does not propagate deletes automatically, as protection). You can enable "Delete marker replication" in the replication rule configuration to replicate delete markers. Permanent deletes (deleting a specific version) are never replicated: designed to protect the destination from accidental/malicious deletes at the source.

  1. What is the minimum object size for the Multi-Part Upload recommendation?
Show answer

AWS recommends 100 MB: larger objects should use Multipart Upload. It is required when an object is > 5 GB (the single PUT limit). Benefits of Multipart: (1) parallel upload (faster), (2) resumable (resume after a lost connection), (3) retry failed parts without restarting everything. If an upload fails midway, you need a lifecycle rule to abort incomplete multipart uploads to avoid paying for storage.

Hands-on Exercises

Part 1: VPC Fundamentals Review

  • Create a VPC with 2 public and 2 private subnets
  • Configure a NAT Gateway for the private subnets
  • Create a Security Group and test connectivity
  • Enable VPC Flow Logs

Part 2: EC2 and Auto Scaling Review

  • Create a Launch Template with User Data
  • Create an Auto Scaling Group with a Target Tracking policy
  • Test scaling by generating CPU load
  • View scaling activities in the console

Part 3: S3 and Storage Review

  • Create a bucket with a lifecycle policy
  • Enable versioning and test delete/restore
  • Configure cross-region replication
  • Test S3 event notifications with Lambda

References


Next lesson →