Best Python code snippet using localstack_python
s3_bucket.py
Source:s3_bucket.py  
...84  if cors_configuration:85    print(f"cors: {cors_configuration}\n")86    add_cors(cors_configuration, bucket_name)87  else:88      delete_cors(bucket_name)89      print(f"Cors configuration deletion request completed... :)") 90def add_notification(Notifications, Bucket):91  bucket_notification = s3r.BucketNotification(Bucket)92    93  if "LambdaConfigurations" in Notifications:94    sw=Notifications['LambdaConfigurations'][0]95    sw['Events'] = sw.pop('Event')96    sw['LambdaFunctionArn'] = sw.pop('Function')  97    if "Filter" in Notifications['QueueConfigurations'][0]:98        sw['Filter']['Key'] = sw['Filter'].pop('S3Key')99        sw['Filter']['Key']['FilterRules'] = sw['Filter']['Key'].pop('Rules')100        for i in range((len(sw['Filter']['Key']['FilterRules']))):101            sw['Filter']['Key']['FilterRules'][i]['Name'] = sw['Filter']['Key']['FilterRules'][i].pop('name')102            sw['Filter']['Key']['FilterRules'][i]['Value'] = sw['Filter']['Key']['FilterRules'][i].pop('value') 103  if "QueueConfigurations" in Notifications:104    sw=Notifications['QueueConfigurations'][0]105    sw['Events'] = sw.pop('Event')106    sw['QueueArn'] = sw.pop('Queue')  107    if "Filter" in sw:108        sw['Filter']['Key'] = sw['Filter'].pop('S3Key')109        sw['Filter']['Key']['FilterRules'] = sw['Filter']['Key'].pop('Rules')110        for i in range((len(sw['Filter']['Key']['FilterRules']))):111            sw['Filter']['Key']['FilterRules'][i]['Name'] = sw['Filter']['Key']['FilterRules'][i].pop('name')112            sw['Filter']['Key']['FilterRules'][i]['Value'] = sw['Filter']['Key']['FilterRules'][i].pop('value') 113  if "TopicConfigurations" in Notifications:114    sw=Notifications['TopicConfigurations'][0]115    sw['Events'] = sw.pop('Event')116    sw['QueueArn'] = sw.pop('Queue')117    if "Filter" in sw:118        sw['Filter']['Key'] = sw['Filter'].pop('S3Key')119        sw['Filter']['Key']['FilterRules'] = sw['Filter']['Key'].pop('Rules')120        for i in range((len(sw['Filter']['Key']['FilterRules']))):121            sw['Filter']['Key']['FilterRules'][i]['Name'] = sw['Filter']['Key']['FilterRules'][i].pop('name')122            sw['Filter']['Key']['FilterRules'][i]['Value'] = sw['Filter']['Key']['FilterRules'][i].pop('value') 123  print(f"transformed data is: {Notifications}")124  response = bucket_notification.put(125      NotificationConfiguration = Notifications126      )127  print(f"Put notification request completed... for {Bucket} :)")  128def delete_notification(Bucket):129    bucket_notification = s3r.BucketNotification(Bucket)130    response = bucket_notification.put(131        NotificationConfiguration={}132        )133    print(f"Put notification delete request completed... for {Bucket} :)")134def add_cors(cors_configuration, bucket_name):135  bucket_cors = s3r.BucketCors(bucket_name)136  cors_rules = []137  bucket_cors.put(138    CORSConfiguration={139      "CORSRules": cors_configuration['CorsRules']140    }141  )142  print(f"Put cors configuration request completed... for {bucket_name} :)")  143def delete_cors(bucket_name):144  bucket_cors = s3r.BucketCors(bucket_name)145  response = bucket_cors.delete()...delete_cors.py
Source:delete_cors.py  
...4id, secret = "ayahghai0juiSie", "quitie*ph3Lah{F"5oss = OssAPI(endpoint, id, secret)6bucket = "bucket-name"7object = "object/name"...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!!
