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

后端 未结 5 807
无人及你
无人及你 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:09

    The exact requirement seems to be that your user has ListBucket permission for your particular bucket AND the ARN is exactly of the form arn:aws:s3:::your_bucket_name.

    I also needed to add a completely new statement to my policy because other permissions like GetObject still require that the ARN ends with /* or some other suitable wildcard.

    {
      "Action": [
        "s3:ListBucket"
      ],
      "Sid": "StmtNNNNNNNNNNNNNNNwholebucket",
      "Resource": [
        "arn:aws:s3:::your_bucket_name"
      ],
      "Effect": "Allow"
    },
    

    To summarize, the important bit for me was that if the ARN is NOT of the form arn:aws:s3:::your_bucket_name/* for ListBucket or you will still get 403 instead of 404.

提交回复
热议问题