, i have setup CF distro with S3 as an origin but i want to make a condition before i serve the content The condition i want it to make sure the request have "user-agent": "example" inside , if she has ONLY then serve the content and if not block it. for now i succeeded to make it work with a S3 bucket policy with condition but the problem is when the content is cached and try to hit the url without the condition it still serve me the website.
how can i implement this solution? i have tried to use lambda@edge on "Viewer request" event but i get 503 error that my lambda dont have enough permissions (with "Origin Request" it worked fine)
bucket policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontServicePrincipalReadOnly",
"Effect": "Allow",
"Principal": {
"Service": "cloudfront.amazonaws.com"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket-name>/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::account-number:distribution/EXAMPLEDISTO"
},
"StringLike": {
"AWS:UserAgent": "*STRING*"
}
}
}
]
}