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

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

    Not Sure if you're looking for this. Making your objects public to everyone solves the 404 issue. However, I do not believe that it is the ideal way to go through with it.

    AWS Cloudfront provides a feature called Origin Access Identity (OAI). How it works is given in detail here.

    Basically in a nutshell, Associate an OAI with your Origin in Cloudfront and update the bucket policy to allow the OAI with GetObject and ListBucket as shown

    {
      "Version": "2008-10-17",
      "Statement": [
        {
          "Sid": "AllowOAIRead",
          "Effect": "Allow",
          "Principal": {
            "AWS": [
              "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity your_OAI_ID"
            ]
          },
          "Action": [
            "s3:GetObject",
            "s3:ListBucket"
          ],
          "Resource": [
            "arn:aws:s3:::your_bucket_name/*",
            "arn:aws:s3:::your_bucket_name"
          ]
        }
      ]
    }
    

提交回复
热议问题