I have looked into below answer but it talks about Origin Access Identity for private content and signed URLs. My content is not private, it is open for public but I dont want other websites to hotlink to my images. In other words, images on my site should be access via my URLs under my domain.
Simple example to restrict access to Cloudfront(S3) files from some users but not others
I've followed below document to create OAI on my CloudFront distribution.
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html
After apply OAI on my distribution, something weird happened. I could access some images, and some I could not.
And when working from localhost I could not access the CloudFront images.
Is there a way I can specify which domains have access to my resources and which ones do not? Like this?
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://example.com/*",
"localhost:*"
]
}
}
}