I am trying to make objects in my S3 bucket accessible via URL, but when I hit the object URL in the browser, I receive the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>0491CC51TEK93R1P</RequestId>
<HostId>aQ9zYuEQ/a5DkwjgbPSkKzfalVuxyYcne8DDIwzSWKo6zhqAovy5U8+PAon5A7OdKfh0KVB/04g=</HostId>
</Error>
Here are my current configurations:
Bucket Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::*****:role/xyz"
},
"Action": "S3:*",
"Resource": "arn:aws:s3:::test/*"
}
]
}
CORS Configuration:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"ETag"
],
"MaxAgeSeconds": 3000
}
]
I have turned off the Block all public access settings in my bucket.
What could be the reason behind this AccessDenied
error when hitting the object URL directly in the browser? Is there something wrong with my bucket policy, CORS configuration, or the settings?
Any insights or suggestions would be greatly appreciated.
I am trying to make objects in my S3 bucket accessible via URL, but when I hit the object URL in the browser, I receive the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>0491CC51TEK93R1P</RequestId>
<HostId>aQ9zYuEQ/a5DkwjgbPSkKzfalVuxyYcne8DDIwzSWKo6zhqAovy5U8+PAon5A7OdKfh0KVB/04g=</HostId>
</Error>
Here are my current configurations:
Bucket Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::*****:role/xyz"
},
"Action": "S3:*",
"Resource": "arn:aws:s3:::test/*"
}
]
}
CORS Configuration:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"ETag"
],
"MaxAgeSeconds": 3000
}
]
I have turned off the Block all public access settings in my bucket.
What could be the reason behind this AccessDenied
error when hitting the object URL directly in the browser? Is there something wrong with my bucket policy, CORS configuration, or the settings?
Any insights or suggestions would be greatly appreciated.
The issue is that the browser has no AWS IAM credentials, this issue does not have anything to do with CORS, you would receive an error from the browser, not from s3. If you want to make requests from the browser you will either have to create an s3 presigned url as Asfar Irshad and Luk2302 suggested:
https://docs.aws.amazon/AmazonS3/latest/userguide/using-presigned-url.html
Or you will have to add the authentication signature to the request headers yourself: https://docs.aws.amazon/AmazonS3/latest/API/sig-v4-authenticating-requests.html
You can also make the objects publicly accessible or go through a cloudfront distribution. In general it's not great to always go through s3, with cloudfront you get caching at the edge and it is cheaper than going through s3 every time.
https://aws.amazon/blogs/networking-and-content-delivery/amazon-s3-amazon-cloudfront-a-match-made-in-the-cloud/