Search code examples
amazon-s3amazon-cloudfront

403 for the new pages in the cloudfront distribution


I have a static web site in the s3 bucket behind the cloudfront distribution. The bucket serves the static site, and the origin is bound to the web site endpoint. I see a couple of pages if they were added before the distribution However, when I upload some new html files, I receive 403 for them. How should I fix this issue?

Bucket policy:

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "AllowCloudFrontServicePrincipal",
            "Effect": "Allow",
            "Principal": {
                "Service": "cloudfront.amazonaws.com"
            },
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::a-test-upload/*",
            "Condition": {
                "StringEquals": {
                    "AWS:SourceArn": "arn:aws:cloudfront::xxx:distribution/yyy"
                }
            }
        }
    ]
}

Solution

  • Try to invalidate cloudfront cache. Go to cloud front distribution and click on invalidation enter "/*". Click on create invalidation.

    If you are trying to access object publicly, then provide public access to s3 bucket objects.