Static Content

Architecture

Use ALB to route static content requests:

  • Path-based routing for /static/*, /assets/*, /images/*
  • Dedicated target groups for static content servers
  • Health checks ensure availability
  • HTTPS for secure delivery

When to Use

Use ALB for static content when:

  • Static assets are served from EC2 or ECS containers
  • You need path-based separation of static and dynamic content
  • You want a unified entry point for your application
  • CloudFront is not required (for global CDN, use CloudFront instead)

Example Configuration

module "content_alb" {
  source  = "registry.patterneddesigns.ca/patterneddesigns/alb/aws"
  version = "3.0.0"

  name    = "content-alb"
  vpc_id  = module.vpc.vpc_id
  subnets = module.vpc.public_subnets

  https_listeners = [{
    port            = 443
    certificate_arn = aws_acm_certificate.main.arn
  }]

  listener_rules = [
    {
      priority = 100
      conditions = [{
        path_pattern = ["/static/*", "/assets/*", "/images/*"]
      }]
      actions = [{
        type             = "forward"
        target_group_arn = aws_lb_target_group.static_servers.arn
      }]
    }
  ]

  # Default action forwards to application servers
  default_action = {
    type             = "forward"
    target_group_arn = aws_lb_target_group.app_servers.arn
  }
}

Considerations

  • For global distribution, combine with CloudFront
  • Consider S3 static hosting for simpler use cases
  • Set appropriate cache headers on static content targets