Home > database >  boto3 print rules from bucket encryption
boto3 print rules from bucket encryption

Time:09-30

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)

CodePudding user response:

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

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