Component 11

SSR CloudFront

Serve a server-rendered site through CloudFront, with two Lambda origins that fail over to one another.

Status

Available component

Deployment scope

Global edge

Example version constraint

~> 0.3

Review published versions ↗

Usage example

Inputs in, outputs out. Illustrative wiring, not a standalone deployment.

Supply the Lambda function URLs, the static assets bucket domains, and the cache and origin request policies. Provide an ACM certificate in us-east-1 for a custom domain. Configure provider requirements and credentials in your root module; check the documentation for all required inputs and version changes.

main.tf
module "cloudfront" {
  source  = "pomo-studio/ssr-cloudfront/aws"
  version = "~> 0.3"

  app_name                    = "my-app"
  primary_lambda_function_url = aws_lambda_function_url.primary.function_url
  dr_lambda_function_url      = aws_lambda_function_url.dr[0].function_url
  static_root_path_patterns   = ["/favicon*", "/robots.txt"]
  enable_dr                   = true
}

Key inputs

  • app_name
  • primary_lambda_function_url
  • dr_lambda_function_url
  • enable_dr
  • enable_custom_domain

Useful outputs

  • id
  • arn
  • domain_name
  • hosted_zone_id

What you get

01

Automatic failover

CloudFront origin groups retry against the DR Lambda on any 5xx, with no health checks.

02

Static and dynamic

Routes /_nuxt/* and nominated root files to S3, everything else to Lambda.

03

Caching for pages built on request

Stale-while-revalidate keeps delivery fast while the Lambda refreshes content.

Built with

  • Amazon CloudFront
  • Lambda
  • S3
  • ACM
  • Terraform