尝试从S3删除文件时为什么出现“无法在执行时删除某些键”的提示?

时间:2019-06-13 06:38:55

标签: amazon-web-services amazon-s3

  1. 我正在使用PHP。
  2. 我拥有IAM的完全访问权限。
  3. 我正在使用API​​中的deleteMatchingObjects。

这是我正在使用的代码:

//AWS
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

S3_removeFilesFromWebsite('010101');

function s3_setClient() {
    // Instantiate the client.
    $s3 = new S3Client([
        //"profile" => "default",
        'version' => 'latest',
        "region" => "us-east-1",
        "http"    => [
            'verify' => false
        ],
        'credentials' => [
            'key'    => $GLOBALS["s3bucket_key"],
            'secret' => $GLOBALS["s3bucket_secret"],
        ],
    ]);

    return $s3;
}

function S3_removeFilesFromWebsite($ID) {
    $from_keyname = 'uploads/'.$ID.'/';
    $uniqueFileName = '77';
    $regexToDelete = "/.*".$uniqueFileName.".*/";

    $s3 = s3_setClient();

    $result = $s3->deleteMatchingObjects($GLOBALS["s3bucket"], $from_keyname, $regexToDelete);
}

这是我不断得到的错误:

<b>Type:</b> exception 'Aws\S3\Exception\DeleteMultipleObjectsException' with message 'Unable to delete certain keys when executing a DeleteMultipleObjects request: 
- {"Key":"uploads\/010101\/77.csv","Code":"AccessDenied","Message":"Access Denied"}
- {"Key":"uploads\/010101\/43434\/77.csv","Code":"AccessDenied","Message":"Access Denied"}' in /Users/vendor/aws/aws-sdk-php/src/S3/BatchDelete.php:200
    enter code here

0 个答案:

没有答案