Saul Salazar/AWS S3 Bucket Policy String Generator

Created Fri, 13 Aug 2021 00:00:00 +0000
96 Words

A simple javascript function to generate policy strings for AWS S3 Buckets that can run on your browser.

You can customize it to your needs :D

Lets start by saying you have A LOT of buckets

var buckets = ['bucketName1', 'bucketName2']

Then you have to iterate/loop through them

buckets.forEach((bucket) => {
  var policy = getPolicyString(bucket)
  console.log(policy)
})

And finally the function, I named it getPolicyString XD

function getPolicyString (bucketName) {
  return `{
    "Statement": [
      {
        "Effect": "Allow",
        "Action": "s3:ListAllMyBuckets",
        "Resource": "arn:aws:s3:::*"
      },
      {
        "Effect": "Allow",
        "Action": "s3:*",
        "Resource": [
          "arn:aws:s3:::${bucketName}",
          "arn:aws:s3:::${bucketName}/*"
        ]
      }
    ]
  }`
}