Skip to content

Instantly share code, notes, and snippets.

@alex-samborskiy
Created December 20, 2020 13:36
Show Gist options
  • Select an option

  • Save alex-samborskiy/be1332e9e411d4bc946175bf8bbdec43 to your computer and use it in GitHub Desktop.

Select an option

Save alex-samborskiy/be1332e9e411d4bc946175bf8bbdec43 to your computer and use it in GitHub Desktop.
[Private sub-folder os S3 bucket] #aws #s3
{
"Sid": "AllowAccessToAllExceptPrivate",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Effect": "Allow",
"NotResource": [
"arn:aws:s3:::bucket/prefix1/prefix2/private/*",
"arn:aws:s3:::bucket/prefix1/prefix2/private"
],
"Principal": {
"AWS": [
"*"
]
}
}
https://stackoverflow.com/questions/20432865/s3-bucket-policy-in-a-public-bucket-make-a-sub-folder-private
After much digging through AWS documentation, as well as many trial and error permutations in the policy editor, I think I have found an adequate solution.
Apparently, AWS provides an option called NotResource (not found in the Policy Generator currently).
The NotResource element lets you grant or deny access to all but a few
of your resources, by allowing you to specify only those resources to
which your policy should not be applied.
With this, I do not even need to play around with conditions. This means that the following statement will work in a bucket policy:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment