无法将我的凭证传递到AWS PHP SDK [英] Can't pass my credentials to AWS PHP SDK

查看:97
本文介绍了无法将我的凭证传递到AWS PHP SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了AWS PHP SDK,并尝试使用SES.我的问题是,无论我做什么,它(显然)正在尝试读取~/.aws/credentials.我目前有此代码:

I installed AWS PHP SDK and am trying to use SES. My problem is that it's (apparently) trying to read ~/.aws/credentials no matter what I do. I currently have this code:

$S3_AK = getenv('S3_AK');
$S3_PK = getenv('S3_PK');
$profile = 'default';
$path = '/home/franco/public/site/default.ini';
$provider = CredentialProvider::ini($profile, $path);
$provider = CredentialProvider::memoize($provider);
$client = SesClient::factory(array(
      'profile' => 'default',
      'region' => 'us-east-1',
      'version' => "2010-12-01",
      'credentials' => [
        'key'    => $S3_AK,
        'secret' => $S3_PK,
      ]
  )); 

并且仍然出现无法从〜/.aws/credentials中读取凭据"错误(相当长的时间).

And am still getting "Cannot read credentials from ~/.aws/credentials" error (after quite a while).

我尝试了'credentials'=> $ provider当然是这个主意,但是由于它不起作用,我恢复了使用硬编码的凭据.我已经抛弃了$ S3_AK和$ S3_PK,它们很好,我实际上在S3上正确使用了它们,但是这里有Zend的包装器.我试过〜/.aws/credentials(没有".ini")以得到相同的结果.这两个文件都具有777权限.

I tried 'credentials' => $provider of course, that was the idea, but as it wasn't working I reverted to hardcoded credentials. I've dumped $S3_AK and $S3_PK and they're fine, I'm actually using them correctly for S3, but there I have Zend's wrapper. I've tried ~/.aws/credentials (no ".ini") to the same result. Both files having 777 permissions.

好奇的信息:我必须将内存限制设置为-1,以便能够var_dump异常.例外情况的html约为200mb.

Curious information: I had to set memory limit to -1 so it would be able to var_dump the exception. The html to the exception is around 200mb.

尽管凭据文件很好,但我还是希望使用环境变量.我只是不明白,即使我已经对凭据进行了硬编码,为什么它似乎仍试图读取文件.

I'd prefer to use the environment variables, all though the credentials file is fine. I just don't understand why it appears to be trying to read the file even though I've hardcoded the credentials.

所以一位朋友向我展示了,我删除了配置文件,还修改了try/catch,发现客户端似乎已正确创建,并且错误来自尝试实际发送电子邮件.

So a friend showed me this, I removed the profile and also modified the try/catch and noticed the client seems to be created properly, and the error comes from trying to actually send an email.

推荐答案

好的,我设法修复了它. 我看不到凭证文件,但这不是我的主意. 发生的事情是成功创建了实际的客户端,但是try/catch也包含了sendEmail.这就是失败的原因. 关于使用显式凭据创建客户端:如果指定区域,请

OK, I managed to fix it. I couldn't read the credentials file but it wasn't exactly my idea. What was happening was that the actual client was being created successfully, but the try/catch also had the sendEmail included. This was what was failing. About creating the client with explicit credentials: If you specify region, it will try and read a credentials file.

关于SendEmail,这是语法 ,对我有用.我还在AWS docs网站上找到了另一个,但是失败了.一定是旧版本的SDK.

About the SendEmail, this is the syntax that worked for me, I'd found another one also in the AWS docs site, and that one failed. It must've been for an older SDK.

这篇关于无法将我的凭证传递到AWS PHP SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆