使用php将文件移动和收集到AmazonS3存储桶
由于SSIS内部的故障和失去耐心,我考虑使用php作为中间人,帮助从AmazonS3存储桶中移动和检索文件 有一个我们似乎无法回避的访问问题 迄今为止的步骤 我们使用IIS Amazon PHP SDK已下载使用php将文件移动和收集到AmazonS3存储桶,php,amazon-web-services,amazon-s3,ssis,Php,Amazon Web Services,Amazon S3,Ssis,由于SSIS内部的故障和失去耐心,我考虑使用php作为中间人,帮助从AmazonS3存储桶中移动和检索文件 有一个我们似乎无法回避的访问问题 迄今为止的步骤 我们使用IIS Amazon PHP SDK已下载 用户C:\inetpub\wwwroot\phpawsaindex.php文件已创建 代码 /error_reporting(E_ERROR); require './aws/aws-autoloader.php'; use Aws\S3\S3Client; use Aws\S3\Exc
用户
C:\inetpub\wwwroot\phpaws
aindex.php
文件已创建
代码
/error_reporting(E_ERROR);
require './aws/aws-autoloader.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = 'BUCKET';
$keyname = 'RKPHPTest.txt';
$filepath = './RKPHPTest.txt';
// Instantiate the client.
$s3 = S3Client::factory(array(
'key' => 'NAME',
'secret' => 'NAME',
'region' => 'eu-west-1',
'version' => 'latest',
'ssl.certificate_authority' => 'C:\inetpub\wwwroot\phpaws\cacert.pem'
));
try {
// Download data.
$result = $s3->getObject(array(
'Bucket' => $bucket,
'Key' => "NAME.txt"
));
// Print the object.
echo $result;
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
echo "<br><br>";
try {
// Upload data.
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'SourceFile' => $filepath,
'ACL' => 'public-read'
));
// Print the URL to the object.
echo $result['ObjectURL'] . "\n";
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
这意味着我们可以执行所有命令。关于如何避免这个错误的任何建议都会很好吗
非常感谢
罗伯特
说清楚 这是列出的完整权限
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::BUCKET/*"
},
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::BUCKET"
}
]
}ShowPolicy{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "importexport:*",
"Resource": "*"
}
]
}
为什么$bucket='bucket'?不应该是“gf redshift upload dev”?很抱歉,没有将arn作为存储桶来显示它的实际内容。请在策略中添加“版本”:“2012-10-17”,并将“arn:aws:s3:::BUCKET*”更改为“arn:aws:s3:::BUCKET/*”,然后重试。在调试策略时,您可能还希望使用IAM策略模拟器或安装awscli并测试基本S3命令。为什么$bucket='bucket'?不应该是“gf redshift upload dev”?很抱歉,没有将arn作为存储桶来显示它的实际内容。请在策略中添加“版本”:“2012-10-17”,并将“arn:aws:s3:::BUCKET*”更改为“arn:aws:s3:::BUCKET/*”,然后重试。在调试策略时,您可能还希望使用IAM策略模拟器或安装awscli并测试基本S3命令。为什么$bucket='bucket'?不应该是“gf redshift upload dev”?很抱歉,没有将arn作为存储桶来显示它的实际内容。请在策略中添加“版本”:“2012-10-17”,并将“arn:aws:s3:::BUCKET*”更改为“arn:aws:s3:::BUCKET/*”,然后重试。在调试策略时,您可能还希望使用IAM策略模拟器或安装awscli和test basic S3命令。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::BUCKET/*"
},
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::BUCKET"
}
]
}ShowPolicy{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "importexport:*",
"Resource": "*"
}
]
}