Set proper endpoint in for S3 Client in Amazon AWS PHP SDK

If you don't want to initialize the client to a specific region and/or you'll need to work with different regions, I have been successful in using the getBucketLocation/setRegion set of calls as follows:

// Bucket location is fetched
$m_bucketLocation = $I_s3->getBucketLocation(array(
        'Bucket' => $s_backupBucket,
));
// Bucket location is specified before operation is made
$I_s3->setRegion($m_bucketLocation['Location']);

I have one extra call, but solved my issue without the need to intervene on the factory.


Got it. The solution was to change the initialisation of the client to:

$client = \Aws\S3\S3Client::factory(array(
  'key' => bla, 
  'secret' => bla, 
  'region' => 'eu-west-1'
));

I.e. rather than specify an endpoint I needed to explicitly set the region in the options array. I guess the example code happens to use whatever the default region is.