To use an S3 bucket as the origin of your CloudFront distribution, you can use either the S3 static website endpoint or the S3 REST API endpoint as the origin domain name. To troubleshoot HTTP 403 (Access Denied) errors, you must know which endpoint type your distribution is using.

To determine if the objects in your S3 bucket are publicly accessible, open the S3 object's URL in a web browser, or run a curl command on the URL.

The following is an example URL of an S3 object:

http://example-bucket.s3-website-us-east-1.amazonaws.com/index.html

If either the web browser or curl command returns an “access denied” error, then the object isn't publicly accessible. If the object isn't publicly accessible, use one of the following methods to allow your REST API endpoint to access the object:

To change the object's encryption settings using the AWS CLI, you must first verify that the object's bucket doesn't have default encryption. If the bucket doesn't have default encryption, run the following AWS CLI command to copy the object to itself. After you copy the object over itself, the object's encryption setting defaults to none.

Warning: Copying the object over itself removes settings for storage-class and website-redirect-location. To maintain these settings in the new object, be sure to explicitly specify storage-class or website-redirect-location values in the copy request. For more information, see Request Headers.

To use an S3 REST API endpoint, your bucket policy must allow s3:GetObject either to public users or to CloudFront's OAI.

Even if you have an explicit allow statement for s3:GetObject in your bucket policy, be sure that there is no explicit deny statement that conflicts with the allow statement. An explicit deny statement always overrides an explicit allow statement.

Review the bucket policy for statements related to the s3:GetObject action.

In the following example policy, there is an explicit allow statement for public access to s3:GetObject. However, there is also an explicit deny statement for s3:GetObject that prevents S3 object access.

Note: CloudFront caches the results of an HTTP 403 (Access Denied) error for up to 5 minutes. After you remove the deny statement from the bucket policy, you might need to run an invalidation on your distribution to remove the object from the cache.

The AWS account that owns the S3 bucket must also own the object

For a bucket policy to apply to external accounts or services (for example, public access or OAI), the AWS account that owns the bucket must also own the objects. Bucket or object ownership is based on the AWS account of the AWS Identity and Access Management (IAM) user or role that created the bucket or object.

Follow these steps to check if the bucket and objects have the same owner:

1. Run this AWS CLI command to get the S3 canonical ID for your AWS account:

aws s3api list-buckets --query Owner.ID

2. Run this command to get the S3 canonical ID of the object owner.

Note: This example command shows a single object, but you can use the list command to check several objects.

aws s3api list-objects --bucket example-bucket --prefix index.html

3. If the canonical IDs don't match, then the bucket and object have different owners.

Note: You can also use the Amazon S3 console to check the bucket and object owners. The owners are found in the Permissions view of the respective bucket or object.

Follow these steps to change the object's owner to the bucket owner:

1. From the object owner's AWS account, run this command to retrieve the access control list (ACL) permissions assigned to the object:

aws s3api get-object-acl --bucket bucket-name --key object-name

2. If the object has bucket-owner-full-control ACL permissions, skip to step #3. If the object doesn't have bucket-owner-full-control ACL permissions, from the object owner's AWS account, run this command to assign bucket owner ACL permissions:

If a requested object doesn't exist in the bucket and the requester doesn't have s3:ListBucket access, then the requester receives an HTTP 403 (Access Denied) error rather than the HTTP 404 (Not Found) error.

To determine if the HTTP 403 error is masking an HTTP 404 error, first check if the object exists in the bucket by opening the bucket from the Amazon S3 console, or by running the head-object AWS CLI command.

Note: References to S3 object names are case-sensitive. Be sure that the object request sent to CloudFront matches the object name exactly. To identify which object CloudFront is requesting from Amazon S3, use server access logging.

If the object is available in the bucket, then the HTTP 403 error isn't masking an HTTP 404 error, and you must verify other configuration requirements to resolve the HTTP 403 error.

If the object isn't available in the bucket, then the HTTP 403 error is masking an HTTP 404 error, and you must resolve the issue related to the missing object.

Note: We don't recommend enabling public s3:ListBucket access because it's not a security best practice.

If clients request the root of your distribution, you must define a default root object

If your distribution doesn't have a default root object defined and a requester doesn't have s3:ListBucket access, the requester receives an HTTP 403 (Access Denied) error instead of an HTTP 404 (Not Found) error when they request the root of your distribution.

Note: We don't recommend enabling public s3:ListBucket access because it's not a security best practice.

If you configured an OAI, the OAI must be included in the S3 bucket policy

If you added an OAI to your CloudFront distribution, you must also include an allow statement for the OAI in the S3 bucket policy.

To verify if your bucket policy allows the OAI, open your S3 bucket in the Amazon S3 console. Then, choose the Permissions view and review the bucket policy. The following is an example allow statement for an OAI: