简体   繁体   中英

boto3 print rules from bucket encryption

Im writing a python script to retrieve information of AWS and im trying to get only the SSEAlgorith but i get TypeError: list indices must be integers or slices, not str Is there any way to do this? I guess it is for the [] inside Rules.

{
    "ServerSideEncryptionConfiguration": {
        "Rules": [
            {
                "ApplyServerSideEncryptionByDefault": {
                    "SSEAlgorithm": "AES256"
                }
            }
        ]
    }
}

This is the code that im using to retrieve the info:

s3 = boto3.client('s3') 
buc = s3.list_buckets()

for i in response['Buckets']:
    enc = s3.get_bucket_encryption(Bucket=i['Name'])
    rules = enc['ServerSideEncryptionConfiguration']['Rules']['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']
    print(rules)

Rules is a list. So assuming you have only one list, it should be:

rules = enc['ServerSideEncryptionConfiguration']['Rules'][0]['ApplyServerSideEncryptionByDefault']['SSEAlgorithm']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM