I am trying to use CloudFront to deliver static assets from an S3 bucket. As I originally found it, the bucket was public and had the following public access settings:
Here was the bucket policy as I originally encountered it:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<BUCKET_NAME>/*"
},
{
"Sid": "2",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E3KB5KQ622F9F3"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<BUCKET_NAME>/*"
}]
}
Now here's what I did:
- Created a new CloudFront distribution with the appropriate origin domain name and restricted bucket access via creating a new Origin Access Identity.
- Updated the S3 bucket policy per their doc examples to restrict access to the canonical user ID. This is what the updated policy looks like:
- Set all of the public access settings to true for the S3 bucket to make it private.
I'm getting access denied whenever I try to access the static resources through the created CDN. In referring to the AWS documentation for restricting S3 bucket access via CloudFront, I'm especially confused about what they want developers to do with the following instructions:
"To specify an origin access identity, use the value of Amazon S3 Canonical User ID
on the Origin Access Identity page in the CloudFront console."