How to use put_bucket_versioning method in localstack

Best Python code snippet using localstack_python

CQ-AWS-S3-007.py

Source:CQ-AWS-S3-007.py Github

copy

Full Screen

...13 14 if response["Status"] == "Suspended":15 # Source for put_bucket_versioning : https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_bucket_versioning16 print("Put bucket versioning")17 response = s3.put_bucket_versioning(Bucket=bucket, VersioningConfiguration={'Status': 'Enabled'})18 print("Put Bucket Versioning Successful")19 print("Run Audit to verify")20 response = s3.get_bucket_versioning(Bucket=bucket)21 print(type(response)) # will output <class 'dict'>22 if response["Status"] == "Enabled": # Expecting 'Status': 'Enabled' during audit.23 print("Status : Enabled | Bucket Versioning is enabled")24 print_statements() # can uncomment this function call for debugging25 return True26 else:27 print("Status : Suspended | Bucket Versioning is not enabled")28 print_statements() # can uncomment this function call for debugging29 return False30 if response["Status"] == "Enabled":31 return True32 33def print_statements(): 34 print("Audit Done")35 print("All Operations completed.")36'''37# Actual working code with correct indentation, proper comments38# and no unnecessary print statements that can slow down the program.39# Below given code should replace above code in production environment.40import json41import boto342import os43import logging44from core import Remediate45@Remediate46def lambda_handler(session, bucket):47 s3 = session.client('s3')48 response = s3.get_bucket_versioning(Bucket=bucket) # 49 50 if response["Status"] == "Suspended": # Checkpoint 1 | If this condition is true, Target is non-compliant. 51 response = s3.put_bucket_versioning(Bucket=bucket, VersioningConfiguration={'Status': 'Enabled'}) # Remediate | will output <class 'dict'>52 response = s3.get_bucket_versioning(Bucket=bucket) # Audit | will output <class 'dict'>53 if response["Status"] == "Enabled": # Expecting 'Status': 'Enabled' | Remediation Successful54 return True55 else: # Expecting 'Status': 'Suspended' | Remediation Unsuccessful56 return False57 if response["Status"] == "Enabled": # Checkpoint 2 | If this condition is true, Target is compliant.58 return True...

Full Screen

Full Screen

bucket_versioning.py

Source:bucket_versioning.py Github

copy

Full Screen

...9token = None # 使用临时密钥需要传入Token,默认为空,可不填10config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象11client = CosS3Client(config)12# 设置存储桶多版本13def put_bucket_versioning():14 #.cssg-snippet-body-start:[put-bucket-versioning]15 response = client.put_bucket_versioning(16 Bucket='examplebucket-1250000000',17 Status='Enabled'18 )19 20 #.cssg-snippet-body-end21# 获取存储桶多版本状态22def get_bucket_versioning():23 #.cssg-snippet-body-start:[get-bucket-versioning]24 response = client.get_bucket_versioning(25 Bucket='examplebucket-1250000000',26 )27 28 #.cssg-snippet-body-end29#.cssg-methods-pragma30# 设置存储桶多版本31put_bucket_versioning()32# 获取存储桶多版本状态33get_bucket_versioning()...

Full Screen

Full Screen

versioning.py

Source:versioning.py Github

copy

Full Screen

...8import boto39from botocore.exceptions import ClientError10 11 12def put_bucket_versioning(): 13 s3_client = boto3.client('s3')14 response = s3_client.put_bucket_versioning(15 Bucket='dub123',## Your Bucket Name here16 VersioningConfiguration={17 'MFADelete': 'Disabled',18 'Status': 'Enabled',19 },20 )21 22 print(response)23 24 25 26def main():27 import argparse28 parser = argparse.ArgumentParser()29 parser.add_argument('bucket_name', help='The name of the bucket.')30 parser.add_argument('--file_name', help='The name of the file to upload.')31 parser.add_argument('--object_key', help='The object key')32 region = 'us-east-1'33 34 args = parser.parse_args()35 #create_bucket(args.bucket_name)36 #list_buckets()37 #upload_file(args.file_name,args.bucket_name, args.object_key)38 get_bucket_versioning()39 put_bucket_versioning()40 bucket_versioning()41 delete_object(region, args.bucket_name, args.object_key)42 delete_bucket(region, args.bucket_name)43 44 45if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful