too long

I am trying to connect to a AWS S3 bucket and list out each of the objects inside the bucket.

When I go to the page I am getting a 500 error that says:

Object of class Generator could not be converted to string

I confirmed my IAM credentials are correct and I have a lot of objects inside the bucket.

Here is my code:

//Include the AWS SDK using the Composer autoloader.
require 'awssdk/aws-autoloader.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
// AWS Info
$bucketName = 'pipedemail';
$IAM_KEY = '*****';
$IAM_SECRET = '******';
// Connect to AWS
try {

    // and on creation. us-east-2 is Ohio, us-east-1 is North Virgina
    $s3 = S3Client::factory(
        array(
            'credentials' => array(
                'key' => $IAM_KEY,
                'secret' => $IAM_SECRET
            ),
            'version' => 'latest',
            'region'  => 'us-east-1'
        )
    );
} catch (Exception $e) {
    // We use a die, so if this fails. It stops here. Typically this is a REST call so this would
    // return a json object.
    die("Error: " . $e->getMessage());
}


// Use the high-level iterators (returns ALL of your objects).
$objects = $s3->getIterator('ListObjects', array('Bucket' => $bucketName));

The line throwing the 500 error is:

$objects = $s3->getIterator('ListObjects', array('Bucket' => $bucketName));

I don't know how to fix this.