SkillSprout
Chapter 5 · Lesson 4
Intermediate
5 min read

Networking for Developers: VPC, ELB, Route 53 and CloudFront

Overview

Developers do not need to design whole networks, but they must understand how requests reach code. A VPC is your private network; Elastic Load Balancing spreads traffic across targets; Route 53 maps names to endpoints; CloudFront caches content close to users.

Imagine a shopping mall. The VPC is the building, the load balancer is the information desk sending visitors to a free shop assistant, Route 53 is the signboard that tells people which building address to use, and CloudFront is a kiosk in every city stocking popular goods so people do not travel to the main store.

DVA-C02 touches these services for Lambda-in-VPC access, ALB targets and health checks, DNS routing policies for blue/green releases, and CloudFront caching by headers, cookies and query strings.

Key Concepts

  • A VPC holds subnets, route tables and security groups; private subnets reach the internet via NAT and AWS services via VPC endpoints.
  • Application Load Balancer works at layer 7: path/host routing, WebSockets and targets of EC2, IP, Lambda or containers.
  • Network Load Balancer works at layer 4 for extreme performance and static IPs.
  • Health checks remove unhealthy targets; the ALB path should check dependencies lightly.
  • Route 53 routing policies: simple, weighted, latency, failover, geolocation, multivalue.
  • CloudFront caches at edge locations using a cache key made of selected headers, cookies and query strings.
  • Origin Access Control (OAC) lets CloudFront read a private S3 bucket.
  • Cache invalidations or versioned file names refresh content; TTLs control freshness.

Detailed Notes

Load balancers for developers

FeatureALBNLB
Layer7 (HTTP/HTTPS/gRPC)4 (TCP/UDP/TLS)
RoutingPath, host, header, query, weighted target groupsPort and protocol
TargetsEC2, IP, Lambda, ECSEC2, IP, ALB
Static IPNo (use Global Accelerator)Yes
AuthenticationOIDC and Cognito on listenerNo

An ALB can invoke a Lambda target, so one function can serve HTTP traffic without API Gateway. The event includes requestContext.elb, and the response must use the ALB format (statusCode, headers, body, isBase64Encoded). Choose ALB for steady high traffic, API Gateway when you need throttling, usage plans, request validation or direct integrations.

Weighted target groups on the listener let you shift traffic gradually between a blue and a green fleet.

yaml
Listener:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    LoadBalancerArn: !Ref Alb
    Port: 443
    Protocol: HTTPS
    Certificates: [{CertificateArn: !Ref Cert}]
    DefaultActions:
      - Type: forward
        ForwardConfig:
          TargetGroups:
            - {TargetGroupArn: !Ref Blue,  Weight: 90}
            - {TargetGroupArn: !Ref Green, Weight: 10}

Health checks and readiness

ALB health checks hit a path such as /health and expect a 200. Return success only when the instance can serve traffic; keep the check cheap and avoid calling every downstream dependency or a single dependency blip would drain the fleet. ECS and EKS add readiness (can take traffic) and liveness (should be restarted) probes with the same idea.

Route 53 routing policies

PolicyUse
SimpleOne record, one or several values
WeightedCanary releases and A/B tests
LatencySend users to the lowest-latency Region
FailoverActive/passive with health checks
GeolocationContent or compliance by user location
MultivalueReturn several healthy IPs

Use alias records to point apex domains at CloudFront, ALB or API Gateway; they are free for AWS targets and follow IP changes.

CloudFront caching

CloudFront decides cache hits using the cache key. A cache policy chooses which headers, cookies and query strings are included and sets TTLs; an origin request policy controls what is forwarded to the origin without being part of the key. Keep the key minimal for a good hit ratio, and include a header such as Accept-Language only when content truly varies.

json
{
  "Name": "lang-aware",
  "MinTTL": 1, "DefaultTTL": 86400, "MaxTTL": 31536000,
  "ParametersInCacheKeyAndForwardedToOrigin": {
    "EnableAcceptEncodingGzip": true,
    "HeadersConfig": {"HeaderBehavior": "whitelist", "Headers": {"Quantity": 1, "Items": ["Accept-Language"]}},
    "CookiesConfig": {"CookieBehavior": "none"},
    "QueryStringsConfig": {"QueryStringBehavior": "none"}
  }
}
bash
aws cloudfront create-invalidation --distribution-id E123ABC --paths "/index.html" "/css/*"

Prefer versioned file names (app.4f3a.js) to invalidations. Use signed URLs or cookies for private content, OAC for S3 origins, Lambda@Edge or CloudFront Functions for lightweight request rewriting, and the us-east-1 Region for ACM certificates used by CloudFront.

Lambda in a VPC, briefly

A function attached to private subnets reaches RDS and ElastiCache, but loses default internet access. Add a NAT gateway for the internet and gateway or interface endpoints for AWS services. The next chapter covers this in depth.

Real World Example

A media site served a news API through an ALB. During sales events, origin load spiked because every request carried a unique tracking query string, which made each request a cache miss. The team created a CloudFront cache policy that ignored tracking parameters but included only the lang header and page query string. Cache hit ratio rose from 22 percent to 91 percent and origin CPU fell by two thirds. They also used Route 53 weighted records to send 5 percent of traffic to a new Region during validation.

Architecture Diagram

Edge to origin request path
Architecture
Delivery
Users
Route 53alias record
CloudFrontcache key
Region
ALBhealth checks
TargetsEC2 / Lambda

DNS resolves to CloudFront, which serves from cache or forwards to the load balancer.

  1. 1Users resolve the domain through a Route 53 alias to CloudFront.
  2. 2CloudFront checks its cache using the configured cache key.
  3. 3On a miss, the request goes to the ALB origin.
  4. 4The ALB sends it to a healthy target and CloudFront caches the response.

Best Practices

  • ✓Keep CloudFront cache keys minimal and use versioned asset names rather than invalidations.
  • ✓Use alias records to point domains at AWS resources.
  • ✓Make health checks cheap and meaningful; separate liveness from readiness.
  • ✓Use weighted routing or weighted target groups for canary releases.
  • ✓Keep S3 origins private with Origin Access Control.

Common Interview Questions

Exam Tips

DVA-C02 focus

  • Cache content per header means adding that header to the cache policy.
  • ACM certificates for CloudFront must be in us-east-1.
  • An ALB can have a Lambda function as a target.
  • Weighted Route 53 records or ALB weighted target groups implement gradual shifting.

Chapter quiz

Architecture Patterns, Resilience and Developer Tooling · 10 questions

  1. 1.A checkout service calls payment, inventory and email synchronously, and slow email calls cause timeouts. What is the best redesign?

  2. 2.A workflow needs ordered steps, compensation on failure and a visual audit of each execution. Which approach is best?

  3. 3.A web tier stores shopping carts in instance memory and needs sticky sessions. How do you make it scale freely?

  4. 4.A consumer processes SQS standard messages and occasionally bills a customer twice. What is the root fix?

  5. 5.A Lambda function calls a partner API that is failing and every invocation waits until timeout. Which combination best limits impact?

  6. 6.A partner allows only 10 requests per second. Your events arrive in bursts of thousands. What is the right design?

  7. 7.A developer wants AI help to generate pytest cases and explain an IAM AccessDenied error inside the IDE. Which service?

  8. 8.A front-end team needs branch preview URLs, hosting, authentication and a data API with minimal infrastructure work. Which service fits?

  9. 9.CloudFront must cache localized pages separately by the Accept-Language header while ignoring tracking query strings. What do you configure?

  10. 10.You want to send 5 percent of traffic to a new version running behind a second ALB target group. What is the simplest mechanism?

0 of 10 answered

Finished this lesson?

0 of 46 lessons done · 0% of the course