dongmeirang4679 2015-06-18 15:39
浏览 73

使用php将文件移动并收集到Amazon S3存储桶

Due to failings within SSIS and losing patience I thought of using php as a go between to help move and retrieve files from the AMAZON S3 bucket.

Theres an access issue that we cant seem to get round

Steps so far

WE use IIS The Amazon PHP SDK was downloaded
user C:\inetpub\wwwroot\phpaws a index.php file was created

the code

/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() . "
";
}

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'] . "
";
} catch (S3Exception $e) {
    echo $e->getMessage() . "
";
}

Then when the API is ran we get on both post and get error msg

Error executing "GetObject" AWS HTTP error: Client error: 403 AccessDenied (client): Access Denied - AccessDeniedAccess

the permissions on account are as follows:

{ 
  "Statement": [ 
    { 
      "Effect": "Allow", 
      "Action": "s3:*", 
      "Resource": "arn:aws:s3:::BUCKET*" 
    }, 
    { 
      "Effect": "Allow", 
      "Action": "s3:ListAllMyBuckets", 
      "Resource": "arn:aws:s3:::*" 
    } 
  ] 
} 

Which means we can do all commands any suggestions on how to get around this error would be great?

Many thanks

Robert


TO be clear

This is the full permissions listed

{
  "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": "*"
    }
  ]
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分