PHP SDK and listObjectsV2

0

I'm using the aws sdk to connect to an s3 bucket. I have built an IAM Policy to allow read using "s3:GetObject", "s3:GetObjectAcl" and "s3:ListBucket" and I can use the AWS cli to view objects and list files. When I use:

    $file = $s3client->getObject([
        'Bucket' => $bucket,
        'Key' => $key,
    ]);
    $body = $file->get('Body');
    $body->rewind();
    echo "Downloaded the file and it begins with: {$body->read(26)}.\n";

I can view file contents but when I try:

 $contents = $s3client->listObjectsV2([
        'Bucket' => $bucket
    ]);
    echo "The contents of your bucket are: \n";
    foreach ($contents['Contents'] as $content) {
        echo $content['Key'] . "\n";

I receive a super helpful error:

Fatal error: Uncaught Error: Class 'SimpleXMLElement' not found in /var/www/html/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php:39 Stack trace: ....

It goes on but I figure it's all trash so not continuing. I grabbed the code straight from: https://docs.aws.amazon.com/code-samples/latest/catalog/php-s3-s3_basics-GettingStartedWithS3.php.html Any suggestions on what is wrong?

nashken
asked 2 years ago920 views
1 Answer
0

sudo apt-get install php-xml

nashken
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions