10

I am hosting a static site on aws via s3/coludfront. Anyway I can force cloudfront to redirect all http request to https version.

aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242

2 Answers2

16

To force http -> https.

  1. Go to the cloudfront distribution
  2. Select the distribution
  3. Go to behaviour
  4. select the one and click edit
  5. Now you have a option of redirecting http -> https
aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242
5

If you're using CloudFormation:

Resources:
  Distribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      ...
      DistributionConfig:
        DefaultCacheBehavior:
          ViewerProtocolPolicy: redirect-to-https
        ...

Previous answer said to use https-only but that will return a 403 (Forbidden) if the viewer sends an HTTP request.

https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CacheBehavior.html

Community
  • 1
  • 1
Andrew Allison
  • 1,122
  • 2
  • 13
  • 30