我在Amazon EC2 Ireland(Ubuntu)中托管了一个项目。
我开发了CodeIgniter,我想将S3用于存储文件。
我使用了三个或四个特定的库来使用S3和CodeIgniter,但没有一个工作。我尝试使用官方AWS SDK for PHP,兼容性测试没问题,但样本不起作用。我认为问题是访问S3。
我在S3 Management中创建了三个存储桶,两个在爱尔兰,一个在美国标准,我可以通过浏览器,S3 Organizer(S3Fox)和Cyberduck访问文件。但我不能访问我的项目。
任何人都可以帮助我吗?
抱歉我的英语不好......
控制器amazona.php:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Amazona extends CI_Controller {
var $bucket = 'cubito';
function __construct()
{
parent::__construct();
$this->load->library('S3');
}
function index()
{
/* $data['files'] = $this->s3->getBucket('cubito'); */
$data['texto'] = "prueba";
$this->load->view('amazona', $data);
}
}
?>
查看amazona.php:
<html>
<head>
<title>prueba</title>
</head>
<body>
<a href="http://cubito.s3.amazonaws.com/imagen.jpg">imagen</a>
<img src="http://cubito.s3.amazonaws.com/imagen.jpg" />
<p><?php echo($texto); ?></p>
<p><?php echo($this->s3->listBuckets()); ?></p>
</body>
</html>
我添加了一个存储桶策略,但仍无效:
{
"Version": "2008-10-17",
"Id": "Policy1351373775750",
"Statement": [
{
"Sid": "Stmt1351373767997",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::cubito",
"arn:aws:s3:::cubito/*"
]
}
]
}
答案 0 :(得分:0)
我认为列出存储桶的s3存储桶策略不正确。 你的桶政策是什么,你可以分享吗?
You Need to include the bucket itself as a resource.
"Resource":["arn:aws:s3:::my_bucket/*", "arn:aws:s3:::my_bucket"]
修改强>
试试这个:(这是一个让IAM用户访问S3的政策)
{
"Statement": [
{
"Sid": "Stmt1351373767997",
"Action": [
"s3:*"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::cubito",
"arn:aws:s3:::cubito/*"
]
},
{
"Effect":"Allow",
"Action":"s3:ListAllMyBuckets",
"Resource":"arn:aws:s3:::*"
}
]
}
试试这个:(这是s3存储桶的策略)
{
"Id": "Policy1351375661442",
"Statement": [
{
"Sid": "Stmt1351375657362",
"Action": "s3:*",
"Effect": "Allow",
"Resource": "arn:aws:s3:::*",
"Principal": {
"AWS": [
"\"AWS\": \"*\""
]
}
}
]
}
答案 1 :(得分:0)
我做到了!!
我更改了s3库中的var $端点。 原文:
public static $endpoint = 's3.amazonaws.com';
改变:
public static $endpoint = 's3-eu-west-1.amazonaws.com';
用我的第一个accesskey和secretkey运行!!!
谢谢大家,抱歉我的英语不好。
¡¡¡格拉西亚斯!!!