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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法