我正在尝试在通过硬编码凭据进行身份验证的同时创建一个 Cloudfront 发行版。
但是,当我运行我的代码时收到此错误 致命错误:未捕获的 Aws\Exception\CredentialsException:无法从 /.aws/credentials 读取凭据
似乎 aws sdk 正在尝试使用此处列出的第二种方法(https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html)进行身份验证- 当您将凭据放在 ./aws 文件夹中
这是我的代码(取自 aws 文档)-知道为什么这不起作用吗?
public function create_cloudfront_client(){
$region='us-east-1';
$client = new Aws\CloudFront\CloudFrontClient([
'profile' => 'default',
'version' => 'latest',
'region' => 'us-east-1',
'debug' => true,
'credentials' =>[
'key' => $this->aws_key,
'secret' => $this->aws_secret,
],
]);
$originName = 'cloudfrontme';
$s3BucketURL = 'https://s3.amazonaws.com/cloudfrontme';
$callerReference = 'uniquestring99';
$comment = 'Created by AWS SDK for PHP';
$cacheBehavior = [
'AllowedMethods' => [
'CachedMethods' => [
'Items' => ['HEAD', 'GET'],
'Quantity' => 2,
],
'Items' => ['HEAD', 'GET'],
'Quantity' => 2,
],
'Compress' => false,
'DefaultTTL' => 0,
'FieldLevelEncryptionId' => '',
'ForwardedValues' => [
'Cookies' => [
'Forward' => 'none',
],
'Headers' => [
'Quantity' => 0,
],
'QueryString' => false,
'QueryStringCacheKeys' => [
'Quantity' => 0,
],
],
'LambdaFunctionAssociations' => ['Quantity' => 0],
'MaxTTL' => 0,
'MinTTL' => 0,
'SmoothStreaming' => false,
'TargetOriginId' => $originName,
'TrustedSigners' => [
'Enabled' => false,
'Quantity' => 0,
],
'ViewerProtocolPolicy' => 'allow-all',
];
UYOU