Search code examples
amazon-web-servicesamazon-s3amazon-cloudfront

Getting 403 (Forbidden) error when accessing static site from custom domain


I'm setting up a static site on S3 and Cloudfront. I've setup SSL, etc. on Cloudfront and I can access the site using the *.cloudfront.net URL. However, when accessing from the custom domain, I get the 403 error. Does anyone know why? The bucket policy is as follows:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "2",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXX"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::www.mydomain.com/*"
        }
    ]
}

This should permit access from the custom domain mydomain.com, right?

For the sake of testing, I've tried setting "Principal": "*", but it still gives 403.

Any help appreciated.


Solution

  • I've fixed it now. I've mistakenly left 'Alternate Domain Names' blank.