Review CloudFront distribution and origin configuration

Review the CloudFront distribution and origins needed by the service, and manage origin access, HTTPS and application security separately.

Description

For a service that uses CloudFront, set Enabled and point the default cache behavior to an entry in Origins.

Potential impact

An unavailable distribution can interrupt delivery or increase origin load. A request that reaches the origin directly bypasses controls applied at CloudFront.

Remediation

Set viewer HTTPS, origin access restrictions and any required authentication or WAF policy. Once deployment finishes, request a real file through the service hostname and check errors and origin load.

Examples

Both excerpts omit the required DefaultCacheBehavior. Supply it and match its target ID to an actual origin before deploying.

Before

yaml
Resources:
  MyDistribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        Enabled: false
        DefaultRootObject: index.html

The first template specifies index.html as the default root object but disables the distribution and defines no origin.

After

yaml
Resources:
  MyDistribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        Enabled: true
        DefaultRootObject: index.html
        Origins:
          - DomainName: www.example.com
            Id: origin1
            CustomOriginConfig:
              HTTPPort: 80
              HTTPSPort: 443
              OriginProtocolPolicy: https-only

The second enables the distribution and connects to origin1 over HTTPS. Viewer connections and direct origin access require their own settings.

References