File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 11# Simply python script to dump list of S3 buckets to a CSV file
22# Boto3 documentation: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-creating-buckets.html
33# To do:
4- # - Add Error handling with botocore if we want to get really fancy with it
4+ # Make this a CLI operation
55
66import csv
77import boto3
8+ from botocore .exceptions import ClientError
89
910# Init boto3 resource for S3
1011# NOTE: The session is created by using creds available under ~/.aws/credentials
@@ -28,11 +29,22 @@ def writeBuckets2csv():
2829 s3listing = bucket ["Name" ]
2930 f .write (s3listing + '\n ' )
3031
32+ def listBucketsWithEncryption ():
33+ for bucket in response ['Buckets' ]:
34+ try :
35+ is_enc = s3 .get_bucket_encryption (Bucket = bucket ['Name' ])
36+ rules = is_enc ['ServerSideEncryptionConfiguration' ]['Rules' ]
37+ print ('Bucket: %s, Encryption: %s' % (bucket ['Name' ]))
38+ except ClientError as e :
39+ if e .response ['Error' ]['Code' ] == 'ServerSideEncryptionConfigurationNotFoundError' :
40+ print ('Bucket: %s, no server-side encryption' % (bucket ['Name' ]))
41+ else :
42+ print ("Bucket: %s, error encountered: %s" % (bucket ['Name' ], e ))
3143
3244def main ():
3345 listS3buckets ()
3446 writeBuckets2csv ()
35-
47+ listBucketsWithEncryption ()
3648
3749if __name__ == "__main__" :
3850 main ()
You can’t perform that action at this time.
0 commit comments