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

查看:33
本文介绍了无法将我的凭证传递给 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 文档站点中找到了另一个,但那个失败了.它一定是用于旧版 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天全站免登陆