Could anyone tell me how to programmatically upload a file to a bucket that's set to be a static website in the S3 console using AWS SDK? The bucket name is foo.ourdomain.com and is hosted in EU-west. I am using the following code to upload the file:
$client = \Aws\S3\S3Client::factory(array('key' => bla, 'secret' => bla));
$client->upload('foo.ourdomain.com', 'test.txt', 'hello world', 'public-read');
But upon using it, I got an exception:
PHP Fatal error: Uncaught Aws\S3\Exception\PermanentRedirectException: AWS Error Code: PermanentRedirect, Status Code: 301, AWS Request ID: -, AWS Error Type: client, AWS Error Message: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint: "foo.ourdomain.com.s3.amazonaws.com"., User-Agent: aws-sdk-php2/2.4.8 Guzzle/3.7.4 curl/7.22.0 PHP/5.3.10-1ubuntu3.8
Since there was no mention of this in the S3 SDK manual, I found a method setEndpoint and adjusted the code as:
$client = \Aws\S3\S3Client::factory(array('key' => bla, 'secret' => bla));
$client->setEndpoint('foo.ourdomain.com.s3.amazonaws.com');
$client->upload('foo.ourdomain.com', 'test.txt', 'hello world', 'public-read');
Since I tried using both the methods, I am still getting the same error, could anybody suggest me a method to fix this, since I am not getting any solutions to it.