Other Articles

CloudFront Distribution – Enforce HTTPS for Viewers

Secure Configuration Checks > AWS

This check ensures that every CloudFront cache behavior redirects HTTP viewers to HTTPS or rejects HTTP. Enforcing HTTPS protects data in transit from interception and tampering.

Check Details

  • Resource: CloudFront Distribution
  • Check: Enforce HTTPS for CloudFront viewers (ViewerHttpsOnly)
  • Risk: Data sent over plain HTTP can be intercepted or modified

Which policy should I choose?

  • Redirect HTTP to HTTPS (redirect-to-https): HTTP requests are redirected to HTTPS. Best for websites, because existing links keep working.
  • HTTPS only (https-only): HTTP requests are rejected with an HTTP 403 error. Best for APIs and clients that never need HTTP.

Remediation via AWS Console

  1. Log in to the AWS Management Console and open the Amazon CloudFront console.

    Amazon CloudFront Console
  2. Navigate to Distributions in the left navigation pane and select the affected distribution.
  3. Open the Behaviors tab.

    CloudFront distribution Behaviors tab
  4. Select the cache behavior you want to update and click Edit.
  5. Under Viewer protocol policy, select either:

    • Redirect HTTP to HTTPS: Automatically redirects HTTP requests to HTTPS.
    • HTTPS only: Allows only HTTPS requests and returns HTTP 403 Forbidden for HTTP requests.
  6. Click Save changes.
  7. Repeat steps 4 to 6 for every cache behavior, including the Default (*) behavior. All behaviors must enforce HTTPS.
  8. Wait for the distribution deployment to complete and verify that no cache behavior allows both HTTP and HTTPS.

Remediation via AWS CLI

  1. Log in to the AWS Management Console and click the CloudShell icon (>_) in the top-right corner.

    AWS CloudShell
  2. Download the current distribution configuration:

    aws cloudfront get-distribution-config \
    --id <distribution-id> > dist-config.json
    
  3. Set the policy on all behaviors. Use https-only instead to reject HTTP:

    POLICY="redirect-to-https"
    ETAG=$(jq -r '.ETag' dist-config.json)
    
    jq --arg p "$POLICY" '.DistributionConfig
    | .DefaultCacheBehavior.ViewerProtocolPolicy = $p
    | .CacheBehaviors.Items |=
    (if . then map(.ViewerProtocolPolicy = $p) else . end)' \
     dist-config.json > updated-config.json
    
    
  4. Apply the updated configuration:

    aws cloudfront update-distribution \
    --id <distribution-id> \
    --if-match "$ETAG" \
    --distribution-config file://updated-config.json
    
  5. Verify the policy. No allow-all should appear:

    aws cloudfront get-distribution-config \
    --id <distribution-id> \
    --query '[DistributionConfig.DefaultCacheBehavior.ViewerProtocolPolicy,
    DistributionConfig.CacheBehaviors.Items[].ViewerProtocolPolicy]'
    

Replace <distribution-id> with your distribution ID, for example E1ABCDEF234567. CloudFront is global, so CloudShell works in any region.

Updated on 03 November, 2026