Question

Cannot get spaces to work with pure php

I always get 400 Bad Request error when I try to list via function.

require ‘vendor/autoload.php’; use Aws\S3\S3Client;

$client = new Aws\S3\S3Client([ ‘version’ => ‘latest’, ‘region’ => ‘nyc3’, ‘driver’=> ‘s3’, ‘endpoint’ => ‘https://nyc3.digitaloceanspaces.com’, ‘credentials’ => [ ‘key’ => getenv(‘xxxx’), ‘secret’ => getenv(‘xxxx’), ], ]);

$spaces = $client->listBuckets(); foreach ($spaces[‘Buckets’] as $space){ echo $space[‘Name’].“\n”; }

ERROR:

Fatal error: Uncaught exception ‘Aws\S3\Exception\S3Exception’ with message ‘Error executing “ListBuckets” on “https://nyc3.digitaloceanspaces.com/”; AWS HTTP error: Client error: GET https://nyc3.digitaloceanspaces.com/ resulted in a 400 Bad Request response: <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>InvalidArgument</Code><RequestId>tx000000000000009191c83-006121e3ea-5 (truncated…) InvalidArgument (client): - <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>InvalidArgument</Code><RequestId>tx000000000000009191c83-006121e3ea-58226b4-nyc3a</RequestId><HostId>58226b4-nyc3a-nyc</HostId></Error>’ GuzzleHttp\Exception\ClientException: Client error: GET https://nyc3.digitaloceanspaces.com/ resulted in a 400 Bad Request response: <?xml version=“1.0” encoding=“UTF-8”?><Error><Code>InvalidArgument</Code><RequestId>tx000000000000009191c83-006121e3ea-5 (truncated…) in /var/www/html/spaces/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /var/www/html/spaces/vendor/guzzlehttp/ in /var/www/html/spaces/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 195

install aws with COMPOSER on my site with pure php


when I try to access with s3cmd it also generates the following error: : 403 - AccessDenied -


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

So I figured the issue, you should remove getenv() function and use string.

use

‘key’ => ‘xxxx’, ‘secret’ => ‘xxxx’

instead of

‘key’ => getenv(‘xxxx’), ‘secret’ => getenv(‘xxxx’)

Same issue here. Anyone found a solution?

I am getting this same thing. Any update on a solution?