How do I have an S3 bucket return 404 (instead of 403) for a key that does not exist in the bucket/

后端 未结 5 799
无人及你
无人及你 2020-11-30 09:23

I am using S3 to store some business critical documents. I want the bucket to return a 404 status code when trying to access an object that does not exist in the bucket.

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 10:13

    I needed to extend the policy like this:

     "Action": [
       "s3:Get*",
       "s3:List*"
     ],
     "Resource": [
       "arn:aws:s3:::bucket_name",
       "arn:aws:s3::: bucket_name/*"
     ],
    

    bucket_name is needed, because without it you don't get 404 for missing objects, but 403 always, bucket_name/* is needed to actually access stuff in the bucket.

提交回复
热议问题