Home > Blockchain >  How do I create an amazon S3 policy that prevents deleting buckets?
How do I create an amazon S3 policy that prevents deleting buckets?

Time:06-06

How do I create an amazon S3 policy that prevents deleting buckets? Currently I have this Json. But I want to disable the possibility of deleting buckets.

How do I do that?

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:*",
                "s3-object-lambda:*"
            ],
            "Resource": "*"
        }
    ]
}

References:

S3: How to grant access to multiple buckets?

s3 Policy has invalid action - s3:ListAllMyBuckets

CodePudding user response:

Try this policy:

{
  "Id": "Policy1654447414913",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1654447407349",
      "Action": [
        "s3:DeleteBucket"
      ],
      "Effect": "Deny",
      "Resource": "arn:aws:s3:::your-example-bucket",
      "Principal": {
        "AWS": [
          "*"
        ]
      }
    }
  ]
}

Don't forget to attach it to the bucket.

The policy was generated with AWS Policy Generator.

CodePudding user response:

S3 buckets can only be deleted if they're empty so what you're wanting may be redundant depending on your use-case.

  • Related