Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba75242

Browse files
committed
Add encryption listing
1 parent 487cc6e commit ba75242

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

s3Ops.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
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

66
import csv
77
import 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

3244
def main():
3345
listS3buckets()
3446
writeBuckets2csv()
35-
47+
listBucketsWithEncryption()
3648

3749
if __name__ == "__main__":
3850
main()

0 commit comments

Comments
 (0)