适用于 PHP 的 SDK 中的 ini 提供程序
Aws\Credentials\CredentialProvider::ini 尝试从共享的 config 和 credentials 文件中加载凭证。默认情况下,SDK 会尝试从位于 ~/.aws/credentials 的共享 Amazon credentials 文件中加载“默认”配置文件。如果 SDK 找到了 AWS_SDK_LOAD_NONDEFAULT_CONFIG 环境变量,还会在位于 ~/.aws/config 的共享 Amazon config 文件中检查是否有“默认”配置文件。
use Aws\Credentials\CredentialProvider; use Aws\S3\S3Client; $provider = CredentialProvider::ini(); // Cache the results in a memoize function to avoid loading and parsing // the ini file on every API operation $provider = CredentialProvider::memoize($provider); $client = new S3Client([ 'region' => 'us-west-2', 'version' => '2006-03-01', 'credentials' => $provider ]);
您可以通过向创建提供程序的函数提供参数来使用自定义配置文件或 .ini 文件位置。
$profile = 'production'; $path = '/full/path/to/credentials.ini'; $provider = CredentialProvider::ini($profile, $path); $provider = CredentialProvider::memoize($provider); $client = new S3Client([ 'region' => 'us-west-2', 'version' => '2006-03-01', 'credentials' => $provider ]);