How to see Read or write access only if we have multiple Buckets in AWS S3 in Python Boto3

VTU Source

I have created multiple Buckets (EX:8Buckets), in that 4 buckets are of only Public-Read,and rest others are Public-Write.Question is how can i see only Read-buckets among those 8 buckets using python boto3 code.Please help me that would be appreciated!

    s3_client = boto3.client('s3')
    buckets = s3_client.list_buckets()
    public_access = False

    for bucket in buckets['Buckets']:
        print(bucket)
        acl_bucket = s3_client.get_bucket_acl(Bucket=bucket['Name'])
        print(acl_bucket)
        for grantee in acl_bucket['Grants']:
            if len(grantee['Grantee']) > 0:
                print(grantee['Grantee'])
                for uri in (grantee['Grantee'].keys()):
                    if uri == 'URI':
                        if grantee['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers':
                            public_access = True
                            print(public_access)
        if public_access == True:
            offenders.append(bucket['Name'])
        public_access = False
    if len(offenders) > 0:
        result = False
python-3.x

Answers

comments powered by Disqus