parameters: (cleaner)
docstring: Deletes all buckets from the client. It will construct a list of resources, delete them, then wait for
      each deletion.
      :param cleaner: A Cleaner object from the main cleanup.py script
      :return: None
docstring_summary: Deletes all buckets from the client. It will construct a list of resources, delete them, then wait for
      each deletion.
      :param cleaner: A Cleaner object from the main cleanup.py script
      :return: None
docstring_tokens: Deletes all buckets from the client . It will construct a list of resources delete them then wait for each deletion . : param cleaner : A Cleaner object from the main cleanup . py script : return : None
function: def delete_s3_buckets(cleaner):
      """
      Deletes all buckets from the client. It will construct a list of resources, delete them, then wait for
      each deletion.
      :param cleaner: A Cleaner object from the main cleanup.py script
      :return: None
      """
      # Note: not a paginated API
      # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#paginators
      # list_buckets() does not have a pagination parameter, nor does it specify how many buckets are returned
      # Construct list
      print('\n\nlooking for buckets with names starting with one  {}'.format(cleaner.describe_prefixes()))
      bucket_name_list = []
  
      try:
          response = cleaner.s3.list_buckets()
  
          for bucket in response['Buckets']:
              bucket_name = bucket['Name']
              if cleaner.has_prefix(bucket_name):
                  print('  found bucket {}'.format(bucket_name))
                  bucket_name_list.append(bucket_name)
      except KeyError as e:
          print("      ERROR: Unexpected KeyError while deleting s3 buckets. {}".format(exception_utils.message(e)))
          return
      except ClientError as e:
          print("      ERROR: Unexpected error for paginator for the s3 client. {}".format(exception_utils.message(e)))
          return
  
      # Delete buckets
      for bucket_name in bucket_name_list:
          _clean_s3_bucket(cleaner, bucket_name)
          try:
              print('    deleting bucket'.format(bucket_name))
              cleaner.s3.delete_bucket(Bucket=bucket_name)
          except ClientError as e:
              print('      ERROR: Failed to delete bucket {0} due to {1}'.format(bucket_name, exception_utils.message(e)))
              code = e.response['Error']['Code']
              if code != "NoSuchBucket":
                  cleaner.add_to_failed_resources('s3', bucket_name)
  
      # Wait for buckets to delete
      for bucket_name in bucket_name_list:
          waiter = cleaner.s3.get_waiter('bucket_not_exists')
          try:
              waiter.wait(Bucket=bucket_name,
                          WaiterConfig={'Delay': cleaner.wait_interval, 'MaxAttempts': cleaner.wait_attempts})
          except botocore.exceptions.WaiterError as e:
              if cleanup_utils.WAITER_ERROR_MESSAGE in exception_utils.message(e):
                  print("      ERROR: Timed out waiting for bucket {} to delete".format(bucket_name))
              else:
                  print("      ERROR: Unexpected error occurred waiting for bucket {0} to delete due to {1}".format(
                      bucket_name, exception_utils.message(e)))
              cleaner.add_to_failed_resources('s3', bucket_name)
function_tokens: def delete_s3_buckets ( cleaner ) : # Note: not a paginated API # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#paginators # list_buckets() does not have a pagination parameter, nor does it specify how many buckets are returned # Construct list print ( '\n\nlooking for buckets with names starting with one  {}' . format ( cleaner . describe_prefixes ( ) ) ) bucket_name_list = [ ] try : response = cleaner . s3 . list_buckets ( ) for bucket in response [ 'Buckets' ] : bucket_name = bucket [ 'Name' ] if cleaner . has_prefix ( bucket_name ) : print ( '  found bucket {}' . format ( bucket_name ) ) bucket_name_list . append ( bucket_name ) except KeyError as e : print ( "      ERROR: Unexpected KeyError while deleting s3 buckets. {}" . format ( exception_utils . message ( e ) ) ) return except ClientError as e : print ( "      ERROR: Unexpected error for paginator for the s3 client. {}" . format ( exception_utils . message ( e ) ) ) return # Delete buckets for bucket_name in bucket_name_list : _clean_s3_bucket ( cleaner , bucket_name ) try : print ( '    deleting bucket' . format ( bucket_name ) ) cleaner . s3 . delete_bucket ( Bucket = bucket_name ) except ClientError as e : print ( '      ERROR: Failed to delete bucket {0} due to {1}' . format ( bucket_name , exception_utils . message ( e ) ) ) code = e . response [ 'Error' ] [ 'Code' ] if code != "NoSuchBucket" : cleaner . add_to_failed_resources ( 's3' , bucket_name ) # Wait for buckets to delete for bucket_name in bucket_name_list : waiter = cleaner . s3 . get_waiter ( 'bucket_not_exists' ) try : waiter . wait ( Bucket = bucket_name , WaiterConfig = { 'Delay' : cleaner . wait_interval , 'MaxAttempts' : cleaner . wait_attempts } ) except botocore . exceptions . WaiterError as e : if cleanup_utils . WAITER_ERROR_MESSAGE in exception_utils . message ( e ) : print ( "      ERROR: Timed out waiting for bucket {} to delete" . format ( bucket_name ) ) else : print ( "      ERROR: Unexpected error occurred waiting for bucket {0} to delete due to {1}" . format ( bucket_name , exception_utils . message ( e ) ) ) cleaner . add_to_failed_resources ( 's3' , bucket_name )