Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maimai-swap/67cd81744343958b872d to your computer and use it in GitHub Desktop.
Save maimai-swap/67cd81744343958b872d to your computer and use it in GitHub Desktop.
Elastic BeanstalkでAWS_SECRET_ACCESS_KEYとAWS_ACCESS_KEY_IDを環境変数に入れた時のウェブアプリ内でのS3Client::factoryの仕方
<?php
require __DIR__.'/../vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Common\Enum\Region;
use Aws\Common\Enum\ClientOptions;
use Aws\Common\Credentials\Credentials;
$credentials = Credentials::fromIni('your-profile-name');
$s3_client = S3Client::factory(array(
ClientOptions::CREDENTIALS => $credentials,
));
var_dump($s3_client);
/*
目的通りのものが出るはず
object(Aws\S3\S3Client)#17 (17) {
["directory":protected]=>
string(50) "/var/app/current/vendor/aws/aws-sdk-php/src/Aws/S3"
["credentials":protected]=>
object(Aws\Common\Credentials\Credentials)#2 (4) {
["key":protected]=>
string(20) "XXXXXXXXXXXXXXXXXX"
["secret":protected]=>
string(40) "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
["token":protected]=>
NULL
["ttd":protected]=>
NULL
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment