如何在wordpress小部件中列出s3桶对象?

I am relatively new to php and wordpress. I'm trying to make a custom widget to display all the folders and files in my bucket in a sidebar. I've tested the code outside of the widget, but when I put it inside a class object and try to drag it into my page with elementor in wordpress, I get a 500 error and I can't update the page. I feel like I'm missing something very obvious, but I've been scratching my head today.

This is running on a qa server using the aws php sdk.

<?php

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

class S3_Widget extends WP_Widget {
  // php classnames and widget name/description added
  function __construct() {
    $widget_options = array(
      'classname' => 's3_widget',
      'description' => 'Add a formatted list of s3 folders & files to the sidebar.'
    );
    parent::__construct(
      's3_widget',
      'S3 Widget',
      $widget_options
    );
  }

  // create the widget output
  function widget( $args, $instance ) {
  require_once 'vendor/aws.phar';

  $bucket = 'gravityforms-bucket';

    // Instantiate the client.
    $s3 = new S3Client([
        'profile' => 'formsS3',
        'version' => 'latest',
        'region'  => 'us-west-2'
    ]);
    echo "<ul>";
    // Use the high-level iterators (returns ALL of your objects).
    try {
    $results = $s3->getPaginator('ListObjects', [
            'Bucket' => $bucket
        ]);

    foreach ($results as $result) {
            foreach ($result['Contents'] as $object) {
                echo "<li>" . $object['Key'] . PHP_EOL . "</li>";
            }
    }
    } catch (S3Exception $e) {
        echo $e->getMessage();
    } catch (Exception $e) {
          echo "<pre>errorMessage::"; echo print_r($e->getMessage(), true); echo "</pre>";
      }

    echo "</ul>";
  }
  function update( $new_instance, $old_instance ) {    
    $instance = $old_instance;
    $instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
    return $instance;
  }
}
// register the widget
function s3_register_widgets() {
  register_widget( 'S3_Widget' );
}
add_action( 'widgets_init', 's3_register_widgets' );

?>

See below my recommendation.

1 - Separate the S3 functions from the widget.

Make a PHP Class that works with S3. This class must returns an Array or List of S3 Bucket Objects.

Test the PHP Class.

2 - Try to integrate the S3 Class into the Widget.

https://docs.aws.amazon.com/AmazonS3/latest/dev/ListingObjectKeysUsingPHP.html

require 'vendor/autoload.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

class S3_List{

  public function s3_listing() {

    $bucket = '*** Your Bucket Name ***';

    // Instantiate the client.
    $s3 = new S3Client([
     'version' => 'latest',
     'region'  => 'us-east-1'
    ]);

    // Use the high-level iterators (returns ALL of your objects).
    try {
     $results = $s3->getPaginator('ListObjects', [
         'Bucket' => $bucket
     ]);

     foreach ($results as $result) {
         foreach ($result['Contents'] as $object) {
             echo $object['Key'] . PHP_EOL;
         }
     }
    } catch (S3Exception $e) {
     echo $e->getMessage() . PHP_EOL;
    }

    // Use the plain API (returns ONLY up to 1000 of your objects).
    try {
     $objects = $s3->listObjects([
         'Bucket' => $bucket
     ]);
     foreach ($objects['Contents']  as $object) {
         echo $object['Key'] . PHP_EOL;
     }
    } catch (S3Exception $e) {
     echo $e->getMessage() . PHP_EOL;
    }
     
  }


}

if ( !function_exists( 'get_s3_bucket' ) ) {

    function get_s3_bucket() {
             $s3_list = new s3_listing();
       return $s3_list->s3_listing();
    }

}

Regards. Ed.

</div>