Amazon SES 从实例配置文件元数据服务器检索凭证时出错.(客户端错误:404) [英] Amazon SES Error retrieving credentials from the instance profile metadata server. (Client error: 404)

查看:60
本文介绍了Amazon SES 从实例配置文件元数据服务器检索凭证时出错.(客户端错误:404)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在让 AWS SES 工作时遇到一些问题;我想从我的网站向用户发送电子邮件.看起来凭证没有被验证,但是我使用了从 IAM 生成的正确凭证(我也尝试了服务器根密钥,它给了我同样的错误).我已经没有关于如何进一步解决/调试的想法,因此任何指导都将不胜感激.

执行时收到错误:

从实例配置文件元数据服务器检索凭据时出错.(客户端错误:404)

采取的步骤

  1. 我已经设置了 SES 并验证了电子邮件地址等

  2. 我创建了一个具有对 SES 的完全访问权限"的 IAM 配置文件

  3. 我已经使用 phar 文件安装了适用于 php 的 AWS 开发工具包

  4. 我已经编写了下面的 php 代码,直接提供了 SES 的正确安全访问代码

<块引用>

需要'aws/aws.phar';使用 AwsSesSesClient;//这里有更多代码$client = SesClient::factory(array('键' =>'xxxxxxxxxxxxxxx','秘密' =>'xxxxxxxxxxxx','地区' =>'us-west-2','版本' =>'2010-12-01'));//代码在这里将 $msg 构建为数组尝试{$result = $client->sendEmail($msg);//保存可用于跟踪请求的MessageId$msg_id = $result->get('MessageId');echo("MessageId: $msg_id");//查看样本输出打印_r($result);} 捕获(异常 $e){echo($e->getMessage());}//查看传递给SDK的原始消息打印_r($msg);

提前感谢您的帮助 - 这始终是一个很棒的社区!!如果我能提供其他任何东西,请告诉我

约翰

解决方案

您可以使用多种方法为您的 SDK 提供凭据.请参阅文档: 向 SDK 提供凭据

1) 使用您创建的 IAM 配置文件中的值设置环境变量:AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY、AWS_DEFAULT_REGION.

2) 除了 1),您还可以创建 ~/.aws/credentials 文件.您可以在此处添加行:
[默认]
aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID
aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
aws_default_region = 区域

1) 或 2) 肯定会起作用,而且很简单.

3) 您还可以创建实例配置文件.您需要创建 IAM 角色和实例配置文件.您的实例需要在创建时分配实例配置文件.请参阅第 183 页(如页面底部所示.主题名称是使用 IAM 角色向应用程序授予权限在 Amazon EC2 实例上运行") 本指南的:AWS IAM 用户指南 了解步骤和过程.这里的秘钥和访问密钥是自动取的,你什么都不用做.你只需要使用步骤1)设置默认区域(即export AWS_DEFAULT_REGION=某个地区).

4) 您已经尝试了第 4 种方法,可能您的设置存在一些我不知道的问题.

Am having some issues getting AWS SES working per below; I want to send an email to users from my website. Looks like the credentials are not being validated, however I have used the correct credentials generated from an IAM (I also tried the server root keys and it gave me the same error). I have run out of ideas of how to resolved/ debug any further so any steer would be greatly appreciated.

Error Received on Execution:

Error retrieving credentials from the instance profile metadata server. (Client error: 404)

Steps Taken

  1. I have setup SES and validated the email addresses etc

  2. I have created a IAM profile with 'Full access to SES'

  3. I have installed the AWS SDK for php using the phar file

  4. I have written the php code below providing the correct security access code directly of the SES

require 'aws/aws.phar';
use AwsSesSesClient;

//More code here

$client = SesClient::factory(array(
    'key' => 'xxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxx',
    'region' => 'us-west-2',
    'version' => '2010-12-01'
));

//code to build the $msg here as array

try{
     $result = $client->sendEmail($msg);

     //save the MessageId which can be used to track the request
     $msg_id = $result->get('MessageId');
     echo("MessageId: $msg_id");

     //view sample output
     print_r($result);
} catch (Exception $e) {
     echo($e->getMessage());
}
//view the original message passed to the SDK
print_r($msg);

Thank you for your help in advance - this is always a great community!! Please let me know if i can provide anything else

John

解决方案

You can provide credentials to your SDK using multiple methods. See the documentation: Providing Credentials to SDK

1) Set the environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION with the values from the IAM profile you created.

2) Instead of 1), you can also create ~/.aws/credentials file. Here you can add the lines:
[default]
aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID
aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
aws_default_region = the region

1) or 2) will definitely work and it is straight forward.

3) You can also create instance profile. You need to create IAM role and instance profile. Your instance needs to have instance profile assigned when it is being created. See page 183 (as indicated on bottom of page. The topic name is "Using an IAM Role to Grant Permissions to Applications Running on Amazon EC2 Instances") of this guide: AWS IAM User Guide to understand the steps and procedure. Here, the secret key and access key are automatically picked up and you don't have to do anything. You just need to set default region using step 1) (i.e, export AWS_DEFAULT_REGION=someregion).

4) You have already tried the 4th method and may be there is some issue in your settings which I am not aware of.

这篇关于Amazon SES 从实例配置文件元数据服务器检索凭证时出错.(客户端错误:404)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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