Richard Hewitt
Richard Hewitt

Reputation: 339

Unable to parse response body into XML: String could not be parsed as XML (View:

I have been tasked with connecting to an s3 bucket and using documentation have the following:

<?php
define('AWS_KEY', 'key in here');
define('AWS_SECRET_KEY', 'key in here');
define('HOST', 'https://console.aws.amazon.com/s3/home?region=us-east-1#');




 use Aws\S3\S3Client;

// Establish connection with DreamObjects with an S3 client.
$client = S3Client::factory(array(
'base_url' => HOST,
'key'      => AWS_KEY,
'secret'   => AWS_SECRET_KEY
 ));

// list owned buckets


$blist = $client->listBuckets();
echo "   Buckets belonging to " . $blist['Owner']['ID'] . ":\n";
foreach ($blist['Buckets'] as $b) {
echo "{$b['Name']}\t{$b['CreationDate']}\n";
}

 // list Bucket contents


 $o_iter = $client->getIterator('ListObjects', array(
'Bucket' => $bucketname
 ));
 foreach ($o_iter as $o) {
  echo "{$o['Key']}\t{$o['Size']}\t{$o['LastModified']}\n";
 }

but I get the error in the title any ideas I have my access keys but i am confused about how to fix this issue ?

Upvotes: 0

Views: 2429

Answers (1)

S&#233;bastien Stormacq
S&#233;bastien Stormacq

Reputation: 14905

It is probably a bad idea to hardcode or to use environment variable to pass your secret key and access key.

A better design pattern would be to leverage EC2 Role or to use the SDK configuration file (see http://docs.aws.amazon.com/aws-sdk-php/guide/latest/credentials.html for details)

The base_url argument you're using is invalid, it is the URL of the console, not the one from the service. You can just ignore this parameter (as per http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#client-configuration-options), the SDK will build it automatically for you

Upvotes: 2

Related Questions