Restricting file types on amazon s3 bucket with a policy

后端 未结 2 1165
眼角桃花
眼角桃花 2021-02-19 15:42

I\'m trying to set up so the only file types the bucket can hold would be png, jpeg, and gif images. I\'m trying to put in a bucket policy like this

{
    \"con         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-19 16:12

    You can use the policy generator for this if you're not sure how to write, for example you would have something like

    {
      "Id": "Policy1464968545158",
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "Stmt1464968483619",
          "Action": [
            "s3:PutObject"
          ],
          "Effect": "Allow",
          "Resource": "arn:aws:s3:::/*.jpg",
          "Principal": "*"
        },
        {
          "Sid": "Stmt1464968543787",
          "Action": [
            "s3:PutObject"
          ],
          "Effect": "Allow",
          "Resource": "arn:aws:s3:::/*.png",
          "Principal": "*"
        }
      ]
    }
    

    As said from doc you can specify multiple resources and aggregate this part, so no need to multiply the statement

        "Resource": [
          "arn:aws:s3:::/*.jpg",
          "arn:aws:s3:::/*.png",
          "arn:aws:s3:::/*.gif",
        ],
    

    so you get something like

    {
        "Id": "Policy1464968545158",
        "Version": "2012-10-17",
        "Statement": [
          {
            "Sid": "Stmt1464968483619",
            "Action": [
              "s3:PutObject"
            ],
            "Effect": "Allow",
            "Resource": [
              "arn:aws:s3:::/*.jpg",
              "arn:aws:s3:::/*.png",
              "arn:aws:s3:::/*.gif",
            ],
            "Principal": "*"
          }
        ]
    }
    

    you can access policy generator when you create your bucket policy

提交回复
热议问题