【发布时间】:2016-04-06 19:43:38
【问题描述】:
AWS S3 正在我的本地主机和我的实时网站上运行,但我的开发服务器(配置完全相同)抛出以下错误:http://xxx.xx.xxx.xxx/latest/meta-data/iam/security-credentials/resulted in a404 Not Found` 响应:检索凭据时出错实例配置文件元数据服务器。
Localhost URL is http://localhost/example
Live URL is http://www.example.com
Development URL is http://dev.example.com
为什么这可以在 localhost 和 live 而不是我的开发服务器上工作?
这是我的示例代码:
$bucket = 'example'
$s3Client = new S3Client([
'region'=>'us-west-2',
'version'=>'2006-03-01',
'key'=>'xxxxxxxxxxxxxxxxxxxxxxxx',
'secret'=>'xxxxxxxxxxxxxxxxxxxxxxxx',
]);
$uniqueFileName = uniqid().'.txt';
$s3Client->putObject([
'Bucket' => $bucket,
'Key' => 'dev/'.$uniqueFileName,
'Body' => 'this is the body!'
]);
这里是政策:
{
"Version": "2012-10-17",
"Id": "Policyxxxxxxxxx",
"Statement": [
{
"Sid": "Stmtxxxxxxxxx",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example/*"
}
]
}
【问题讨论】:
-
我认为您已编辑的 xxx.xx.xxx.xx 是 169.254.169.254?
-
这是 EC2 元数据虚拟服务器的标准 IP 地址,您的应用程序或 AWS 库会在其中获取基于实例角色的临时凭证。如果一切都相同,为什么它在 localhost 上工作似乎是个谜。您是否使用实例角色?两台 EC2 机器是否配置了相同的角色?
-
ec2metadata命令行实用程序访问同一端点。
标签: amazon-web-services amazon-s3