Ribens
Ribens

Reputation: 326

How to get a file in a S3 bucket that was uploaded using Cloudfront?

I am currently trying to implement Cloudfront upload (POST/PUT methods) on an existing S3 bucket.

My Cloudfront distribution seems well-configured. I am using Cloudfront signed urls to upload my files in the S3 bucket. It works fine. Once the files uploaded, I can access them using Cloudfront signed url. It is fine too.

But I observe that I cannot access the uploaded files (via Cloudfront) using the AWS credentials (access_key_id & secret_key). Everytime, I try this, I receive an AccessDenied error code.

I feel like something is missing in the configuration of the S3 bucket policy. Here is my current S3 bucket policy:

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Principal": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXXXXXX",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::XXXXX-XXXXXX-XXXX/*"
        }
    ]
}

Did I miss something or is it just impossible?

Upvotes: 1

Views: 1411

Answers (1)

romainsalles
romainsalles

Reputation: 2143

I did have the same issue once.

Try to add the header "x-amz-acl=bucket-owner-full-control" to the upload request and that should do the trick.

Upvotes: 1

Related Questions