2017-07-06 8 views
1

私は、コードの下に使用してAmazon S3の上のバケットの存在をチェックしようとしています:欠落必要なクライアント構成オプション:地域

$credentials = new Aws\Common\Credentials\Credentials($creds['access_key_id'], $creds['secret_access_key']); 
$client = Aws\S3\S3Client::factory(array('credentials' => $credentials)); 
if(! $client->doesBucketExist($creds['bucket'])) { 
    throw new Exception("Bucket (" . $creds['bucket'] . ") does not exist."); 
} 

それは、ローカルホスト(WAMP)に取り組んでいるが、私は、サーバー上でこれをしようとしたとき、それが機能していません。私は次のエラーが発生しています:

Missing required client configuration options: region: (string) A "region" configuration value is required for the "s3" service (e.g., "us-west-2"). A list of available public regions and endpoints can be found at http://docs.aws.amazon.com/general/latest/gr/rande.html . version: (string) A "version" configuration value is required. Specifying a version constraint ensures that your code will not be affected by a breaking change made to the service. For example, when using Amazon S3, you can lock your API version to "2006-03-01". Your build of the SDK has the following version(s) of "s3": * "2006-03-01" You may provide "latest" to the "version" configuration value to utilize the most recent available API version that your client's API provider can find. Note: Using 'latest' in a production application is not recommended. A list of available API versions can be found on each client's API documentation page: http://docs.aws.amazon.com/aws-sdk-php/v3/api/index.html . If you are unable to load a specific API version, then you may need to update your copy of the SDK.

私はなぜそれがサーバー上で動作していないが、同じコードがlocalhostで動作しているのかわかりません。

+0

おそらくあなたのAWSのデフォルトの領域設定は、サーバー上のローカルホストではなく、上の(自分のホームディレクトリにある.awsフォルダ)をプロファイルしていますか? – RaGe

答えて

2

デフォルトに頼るのではなく、s3クライアントを作成するときに明示的に領域を設定します。

use Aws\Credentials\Credentials; 
use Aws\S3\S3Client; 

$result = $stsClient->getSessionToken(); 

$credentials = new Credentials(
    $result['Credentials']['AccessKeyId'], 
    $result['Credentials']['SecretAccessKey'], 
    $result['Credentials']['SessionToken'] 
); 

$s3Client = new S3Client([ 
    'version'  => '2006-03-01', 
    'region'  => 'us-west-2', 
    'credentials' => $credentials 
]); 
+0

なぜAws \ Common \ Credentials \ Credentialsの代わりに 'Aws \ Credentials \ Credentials'を提供する必要がありますか – EmptyData

+0

あなたが使用するaws-sdk-phpのバージョンに依存します。 2.8対3.0共通は遠ざかった。 [1](https://github.com/aws/aws-sdk-php/tree/master/src/Credentials)vs [2](https://github.com/aws/aws-sdk-php/)を参照してください。ツリー/ 2.8/src/Aws/Common/Credentials) – RaGe

関連する問題