S3: make a public folder private again?

前端 未结 12 2006
北恋
北恋 2021-01-30 20:16

How do you make an AWS S3 public folder private again?

I was testing out some staging data, so I made the entire folder public within a bucket. I\'d like to restrict it

12条回答
  •  独厮守ぢ
    2021-01-30 20:25

    As of now, according to the boto docs you can do it this way

    #!/usr/bin/env python
    #remove public read right for all keys within a directory
    
    #usage: remove_public.py bucketName folderName
    
    import sys
    import boto
    
    bucketname = sys.argv[1]
    dirname = sys.argv[2]
    s3 = boto.connect_s3()
    bucket = s3.get_bucket(bucketname)
    
    keys = bucket.list(dirname)
    
    for k in keys:
        # options are 'private', 'public-read'
        # 'public-read-write', 'authenticated-read'
        k.set_acl('private') 
    

    Also, you may consider to remove any bucket policies under permissions tab of s3 bucket.

提交回复
热议问题