Best Python code snippet using localstack_python
enable_logging.py
Source:enable_logging.py  
...9        client = boto3.client('s3', region_name='us-east-1')10        response = client.list_buckets()11        log = client.get_bucket_logging(Bucket=bucket["Name"])12        if 'LoggingEnabled' not in log:13            client.put_bucket_logging(14                Bucket=bucket['Name'],15                BucketLoggingStatus={16                    'LoggingEnabled': {17                        'TargetBucket': s3_logging_target_bucket,18                        'TargetPrefix': bucket['Name']19                    }20                }21            )22            print('Enable logging on Bucket =%s' % (bucket['Name']))23        else:24            print('Bucket =%s, Logging: %s' % (bucket['Name'], log['LoggingEnabled']))25    elif loc['LocationConstraint'] == 'eu-west-1':26        client = boto3.client('s3', region_name='eu-west-1')27        response = client.list_buckets()28        log = client.get_bucket_logging(Bucket=bucket["Name"])29        if 'LoggingEnabled' not in log:30            client.put_bucket_logging(31                Bucket=bucket['Name'],32                BucketLoggingStatus={33                    'LoggingEnabled': {34                        'TargetBucket': '911833893017-lpfs-s3-logs-us-east-1',35                        'TargetPrefix': bucket['Name']36                    }37                }38            )39            print('Enable logging on Bucket =%s' % (bucket['Name']))40        else:41            print('Bucket =%s, Logging: %s' % (bucket['Name'], log['LoggingEnabled']))42    elif loc['LocationConstraint'] == 'ap-southeast-2':43        client = boto3.client('s3', region_name='ap-southeast-2')44        response = client.list_buckets()45        log = client.get_bucket_logging(Bucket=bucket["Name"])46        if 'LoggingEnabled' not in log:47            client.put_bucket_logging(48                Bucket=bucket['Name'],49                BucketLoggingStatus={50                    'LoggingEnabled': {51                        'TargetBucket': '911833893017-lpfs-s3-logs-us-east-1',52                        'TargetPrefix': bucket['Name']53                    }54                }55            )56            print('Enable logging on Bucket =%s' % (bucket['Name']))57        else:58            print('Bucket =%s, Logging: %s' % (bucket['Name'], log['LoggingEnabled']))59    elif loc['LocationConstraint'] == 'us-east-2':60        client = boto3.client('s3', region_name='us-east-2')61        response = client.list_buckets()62        log = client.get_bucket_logging(Bucket=bucket["Name"])63        if 'LoggingEnabled' not in log:64            client.put_bucket_logging(65                Bucket=bucket['Name'],66                BucketLoggingStatus={67                    'LoggingEnabled': {68                        'TargetBucket': '911833893017-lpfs-s3-logs-us-east-1',69                        'TargetPrefix': bucket['Name']70                    }71                }72            )73            print('Enable logging on Bucket =%s' % (bucket['Name']))74        else:75            print('Bucket =%s, Logging: %s' % (bucket['Name'], log['LoggingEnabled']))76    elif loc['LocationConstraint'] == 'eu-west-2':77        client = boto3.client('s3', region_name='eu-west-2')78        response = client.list_buckets()79        log = client.get_bucket_logging(Bucket=bucket["Name"])80        if 'LoggingEnabled' not in log:81            client.put_bucket_logging(82                Bucket=bucket['Name'],83                BucketLoggingStatus={84                    'LoggingEnabled': {85                        'TargetBucket': '911833893017-lpfs-s3-logs-us-east-1',86                        'TargetPrefix': bucket['Name']87                    }88                }89            )90            print('Enable logging on Bucket =%s' % (bucket['Name']))91        else:92            print('Bucket =%s, Logging: %s' % (bucket['Name'], log['LoggingEnabled']))93    elif loc['LocationConstraint'] == 'eu-central-1':94        client = boto3.client('s3', region_name='eu-central-1')95        response = client.list_buckets()96        log = client.get_bucket_logging(Bucket=bucket["Name"])97        if 'LoggingEnabled' not in log:98            client.put_bucket_logging(99                Bucket=bucket['Name'],100                BucketLoggingStatus={101                    'LoggingEnabled': {102                        'TargetBucket': '911833893017-lpfs-s3-logs-eu-central-1',103                        'TargetPrefix': bucket['Name']104                    }105                }106            )107            print('Enable logging on Bucket =%s' % (bucket['Name']))108        else:...bucket_logging.py
Source:bucket_logging.py  
...9token = None               # 使ç¨ä¸´æ¶å¯é¥éè¦ä¼ å
¥Tokenï¼é»è®¤ä¸ºç©º,å¯ä¸å¡«10config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token)  # è·åé
置对象11client = CosS3Client(config)12# å¼å¯å卿¡¶æ¥å¿æå¡13def put_bucket_logging():14    #.cssg-snippet-body-start:[put-bucket-logging]15    response = client.put_bucket_logging(16        Bucket='examplebucket-1250000000',17        BucketLoggingStatus={18            'LoggingEnabled': {19                'TargetBucket': 'logging-bucket-1250000000',20                'TargetPrefix': 'string'21            }22        }23    )24    25    #.cssg-snippet-body-end26# è·åå卿¡¶æ¥å¿æå¡27def get_bucket_logging():28    #.cssg-snippet-body-start:[get-bucket-logging]29    response = client.get_bucket_logging(30        Bucket='examplebucket-1250000000'31    )32    33    #.cssg-snippet-body-end34#.cssg-methods-pragma35# å¼å¯å卿¡¶æ¥å¿æå¡36put_bucket_logging()37# è·åå卿¡¶æ¥å¿æå¡38get_bucket_logging()...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
