Review CloudFront content delivery configuration

Configure the CloudFront distribution and origin needed by the service.

Description

For an active service that uses CloudFront, set enabled = true and point origin to the content source. A retired service can keep its distribution disabled.

Potential impact

A disabled distribution cannot serve files. Without S3 read access, CloudFront cannot fetch an object on a cache miss.

Remediation

Connect the default cache behavior to the origin ID and supply the other required distribution settings. After deployment, request a new, uncached object through the service hostname to verify origin access. If the origin is private, check that a direct anonymous request for the same object fails.

Examples

The second excerpt uses the S3 bucket’s regional endpoint and an existing origin access identity (OAI). Supply the bucket and local.s3_origin_id, replace the example OAI path and grant that identity read access to the intended objects.

Before

hcl
resource "aws_cloudfront_distribution" "example" {
  enabled = false
}

After

hcl
resource "aws_cloudfront_distribution" "example" {
  origin {
    domain_name = aws_s3_bucket.b.bucket_regional_domain_name
    origin_id   = local.s3_origin_id

    s3_origin_config {
      origin_access_identity = "origin-access-identity/cloudfront/ABCDEFG1234567"
    }
  }

  enabled = true
}

References