#!/usr/bin/env python3 import boto3 def main(): client = boto3.client('s3') response = client.list_buckets() for bucket in response['Buckets']: response = client.get_bucket_logging(Bucket=bucket['Name']) if 'LoggingEnabled' in response: if 's3/security-475275892927' in response['LoggingEnabled']['TargetPrefix']: print(bucket['Name']) if __name__ == '__main__': main()