skip to Main Content

I have an S3 bucket named my.example.com, and within it I have the folder Folder1.

I’m confused about why the following policy doesn’t let me download files from Folder1.

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Sid": "MyPolicy",
         "Effect": "Allow",
         "Action": "s3:Get*",
         "Resource": "arn:aws:s3:::my.example.com",
         "Condition": {
            "StringLike": {
               "s3:prefix": [
                  "Folder1/*"
               ]
            }
         }
      }
   ]
}

However, this policy does let me download files

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Sid": "MyPolicy",
         "Effect": "Allow",
         "Action": "s3:Get*",
         "Resource": "arn:aws:s3:::my.example.com/Folder1/*"
      }
   ]
}

Why doesn’t the first policy work?

2

Answers


  1. According to this page at AWS: https://docs.aws.amazon.com/AmazonS3/latest/userguide/amazon-s3-policy-keys.html

    The prefix key automatically matches anything after the prefix, so you shouldn’t need the asterisk. So perhaps something like:

    "StringEquals": {
      "s3:prefix": [
        "Folder1"
      ]
    }
    

    Would work?

    Login or Signup to reply.
  2. Your resource:

    "Resource": "arn:aws:s3:::my.example.com",
    

    is for bucket only, not for any objects in the bucket. Thus, for your policy to apply to the objects it should be:

    "Resource": "arn:aws:s3:::my.example.com/*",
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search